mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-25 22:52:53 -04:00 
			
		
		
		
	Merge branch 'l9' into v5-stable
This commit is contained in:
		
						commit
						cf9d9c3efe
					
				
							
								
								
									
										4
									
								
								.github/workflows/release.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.github/workflows/release.yml
									
									
									
									
										vendored
									
									
								
							| @ -12,13 +12,13 @@ jobs: | ||||
|       - name: Setup PHP | ||||
|         uses: shivammathur/setup-php@v2 | ||||
|         with: | ||||
|           php-version: 7.4 | ||||
|           php-version: 8.1 | ||||
|           extensions: mysql, mysqlnd, sqlite3, bcmath, gd, curl, zip, openssl, mbstring, xml | ||||
| 
 | ||||
|       - name: Checkout code | ||||
|         uses: actions/checkout@v1 | ||||
|         with: | ||||
|           ref: v5-stable | ||||
|           ref: l9 | ||||
|            | ||||
|       - name: Copy .env file | ||||
|         run: | | ||||
|  | ||||
| @ -1 +1 @@ | ||||
| 5.4.12 | ||||
| 5.5.0 | ||||
| @ -66,39 +66,25 @@ class BackupUpdate extends Command | ||||
|                 $this->handleOnDb(); | ||||
|             } | ||||
| 
 | ||||
|         MultiDB::setDB($current_db); | ||||
|          | ||||
|             MultiDB::setDB($current_db); | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private function handleOnDb() | ||||
|     { | ||||
|         set_time_limit(0); | ||||
|          | ||||
|         Backup::whereHas('activity')->whereRaw('html_backup IS NOT NULL')->cursor()->each( function ($backup) { | ||||
| 
 | ||||
|                  | ||||
|                 if(strlen($backup->html_backup) > 1 && $backup->activity->invoice->exists()){ | ||||
| 
 | ||||
|                     $client = $backup->activity->invoice->client; | ||||
|                     $backup->storeRemotely($backup->html_backup, $client); | ||||
| 
 | ||||
|                 }else if(strlen($backup->html_backup) > 1 && $backup->activity->quote->exists()){ | ||||
| 
 | ||||
|                     $client = $backup->activity->quote->client; | ||||
|                     $backup->storeRemotely($backup->html_backup, $client); | ||||
| 
 | ||||
|                 }else if(strlen($backup->html_backup) > 1 && $backup->activity->credit->exists()){ | ||||
| 
 | ||||
|                     $client = $backup->activity->credit->client; | ||||
|                     $backup->storeRemotely($backup->html_backup, $client); | ||||
| 
 | ||||
|                 } | ||||
| 
 | ||||
|              | ||||
|         Backup::whereHas('activity')->whereRaw('html_backup IS NOT NULL')->cursor()->each(function ($backup) { | ||||
|             if (strlen($backup->html_backup) > 1 && $backup->activity->invoice->exists()) { | ||||
|                 $client = $backup->activity->invoice->client; | ||||
|                 $backup->storeRemotely($backup->html_backup, $client); | ||||
|             } elseif (strlen($backup->html_backup) > 1 && $backup->activity->quote->exists()) { | ||||
|                 $client = $backup->activity->quote->client; | ||||
|                 $backup->storeRemotely($backup->html_backup, $client); | ||||
|             } elseif (strlen($backup->html_backup) > 1 && $backup->activity->credit->exists()) { | ||||
|                 $client = $backup->activity->credit->client; | ||||
|                 $backup->storeRemotely($backup->html_backup, $client); | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -36,8 +36,8 @@ use App\Models\GroupSetting; | ||||
| use App\Models\Invoice; | ||||
| use App\Models\InvoiceInvitation; | ||||
| use App\Models\Payment; | ||||
| use App\Models\PaymentHash; | ||||
| use App\Models\Paymentable; | ||||
| use App\Models\PaymentHash; | ||||
| use App\Models\Product; | ||||
| use App\Models\Project; | ||||
| use App\Models\Quote; | ||||
| @ -61,13 +61,11 @@ use Illuminate\Support\Str; | ||||
| use Mail; | ||||
| use Symfony\Component\Console\Input\InputOption; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * Class CheckDb. | ||||
|  */ | ||||
| class CheckDb extends Command | ||||
| { | ||||
| 
 | ||||
|     protected $signature = 'ninja:check-db'; | ||||
| 
 | ||||
|     protected $description = 'Check MultiDB'; | ||||
| @ -118,33 +116,30 @@ class CheckDb extends Command | ||||
| 
 | ||||
|     public function handle() | ||||
|     { | ||||
|         $this->LogMessage('Checking - V5_DB1'); | ||||
| 
 | ||||
|         $this->LogMessage("Checking - V5_DB1"); | ||||
| 
 | ||||
|         foreach($this->entities as $entity) { | ||||
|              | ||||
|         foreach ($this->entities as $entity) { | ||||
|             $count_db_1 = $entity::on('db-ninja-01')->count(); | ||||
|             $count_db_2 = $entity::on('db-ninja-02a')->count(); | ||||
| 
 | ||||
|             $diff = $count_db_1 - $count_db_2; | ||||
| 
 | ||||
|             if($diff != 0) | ||||
|             if ($diff != 0) { | ||||
|                 $this->logMessage("{$entity} DB1: {$count_db_1} - DB2: {$count_db_2} - diff = {$diff}"); | ||||
| 
 | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         $this->LogMessage("Checking - V5_DB2"); | ||||
| 
 | ||||
|         foreach($this->entities as $entity) { | ||||
|         $this->LogMessage('Checking - V5_DB2'); | ||||
| 
 | ||||
|         foreach ($this->entities as $entity) { | ||||
|             $count_db_1 = $entity::on('db-ninja-02')->count(); | ||||
|             $count_db_2 = $entity::on('db-ninja-01a')->count(); | ||||
| 
 | ||||
|             $diff = $count_db_1 - $count_db_2; | ||||
| 
 | ||||
|             if($diff != 0) | ||||
|             if ($diff != 0) { | ||||
|                 $this->logMessage("{$entity} DB1: {$count_db_1} - DB2: {$count_db_2} - diff = {$diff}"); | ||||
| 
 | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| @ -154,5 +149,4 @@ class CheckDb extends Command | ||||
|         $this->info($str); | ||||
|         $this->log .= $str."\n"; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -51,10 +51,12 @@ use Illuminate\Support\Str; | ||||
| class CreateAccount extends Command | ||||
| { | ||||
|     use MakesHash, GeneratesCounter; | ||||
| 
 | ||||
|     /** | ||||
|      * @var string | ||||
|      */ | ||||
|     protected $description = 'Create Single Account'; | ||||
| 
 | ||||
|     /** | ||||
|      * @var string | ||||
|      */ | ||||
| @ -82,12 +84,10 @@ class CreateAccount extends Command | ||||
|         $this->warmCache(); | ||||
| 
 | ||||
|         $this->createAccount(); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private function createAccount() | ||||
|     { | ||||
| 
 | ||||
|         $account = Account::factory()->create(); | ||||
|         $company = Company::factory()->create([ | ||||
|             'account_id' => $account->id, | ||||
| @ -131,10 +131,9 @@ class CreateAccount extends Command | ||||
|             'settings' => null, | ||||
|         ]); | ||||
| 
 | ||||
|         CreateCompanyPaymentTerms::dispatchNow($company, $user); | ||||
|         CreateCompanyTaskStatuses::dispatchNow($company, $user); | ||||
|         VersionCheck::dispatchNow(); | ||||
| 
 | ||||
|         CreateCompanyPaymentTerms::dispatchSync($company, $user); | ||||
|         CreateCompanyTaskStatuses::dispatchSync($company, $user); | ||||
|         VersionCheck::dispatchSync(); | ||||
|     } | ||||
| 
 | ||||
|     private function warmCache() | ||||
| @ -164,5 +163,4 @@ class CreateAccount extends Command | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -48,10 +48,12 @@ use Illuminate\Support\Str; | ||||
| class CreateTestData extends Command | ||||
| { | ||||
|     use MakesHash, GeneratesCounter; | ||||
| 
 | ||||
|     /** | ||||
|      * @var string | ||||
|      */ | ||||
|     protected $description = 'Create Test Data'; | ||||
| 
 | ||||
|     /** | ||||
|      * @var string | ||||
|      */ | ||||
| @ -66,14 +68,16 @@ class CreateTestData extends Command | ||||
|      */ | ||||
|     public function handle() | ||||
|     { | ||||
|         if(config('ninja.is_docker')) | ||||
|         if (config('ninja.is_docker')) { | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|     if (!$this->confirm('Are you sure you want to inject dummy data?')) | ||||
|         return; | ||||
|         if (! $this->confirm('Are you sure you want to inject dummy data?')) { | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         $this->invoice_repo = new InvoiceRepository(); | ||||
|          | ||||
| 
 | ||||
|         $this->info(date('r').' Running CreateTestData...'); | ||||
|         $this->count = $this->argument('count'); | ||||
| 
 | ||||
| @ -125,14 +129,14 @@ class CreateTestData extends Command | ||||
|             'is_admin' => 1, | ||||
|             'is_locked' => 0, | ||||
|             'notifications' => CompanySettings::notificationDefaults(), | ||||
|            // 'permissions' => '',
 | ||||
|             // 'permissions' => '',
 | ||||
|             'settings' => null, | ||||
|         ]); | ||||
| 
 | ||||
|         Product::factory()->count(50)->create([ | ||||
|                 'user_id' => $user->id, | ||||
|                 'company_id' => $company->id, | ||||
|             ]); | ||||
|             'user_id' => $user->id, | ||||
|             'company_id' => $company->id, | ||||
|         ]); | ||||
| 
 | ||||
|         $this->info('Creating '.$this->count.' clients'); | ||||
| 
 | ||||
| @ -219,15 +223,14 @@ class CreateTestData extends Command | ||||
|             'is_admin' => 1, | ||||
|             'is_locked' => 0, | ||||
|             'notifications' => CompanySettings::notificationDefaults(), | ||||
|          //   'permissions' => '',
 | ||||
|             //   'permissions' => '',
 | ||||
|             'settings' => null, | ||||
|         ]); | ||||
| 
 | ||||
|         Product::factory()->count(50)->create([ | ||||
|                 'user_id' => $user->id, | ||||
|                 'company_id' => $company->id, | ||||
|             ]); | ||||
| 
 | ||||
|             'user_id' => $user->id, | ||||
|             'company_id' => $company->id, | ||||
|         ]); | ||||
| 
 | ||||
|         $this->count = $this->count * 10; | ||||
| 
 | ||||
| @ -317,14 +320,14 @@ class CreateTestData extends Command | ||||
|             'is_admin' => 1, | ||||
|             'is_locked' => 0, | ||||
|             'notifications' => CompanySettings::notificationDefaults(), | ||||
|          //   'permissions' => '',
 | ||||
|             //   'permissions' => '',
 | ||||
|             'settings' => null, | ||||
|         ]); | ||||
| 
 | ||||
|         Product::factory()->count(15000)->create([ | ||||
|                 'user_id' => $user->id, | ||||
|                 'company_id' => $company->id, | ||||
|             ]); | ||||
|             'user_id' => $user->id, | ||||
|             'company_id' => $company->id, | ||||
|         ]); | ||||
| 
 | ||||
|         $this->count = $this->count * 10; | ||||
| 
 | ||||
| @ -382,30 +385,29 @@ class CreateTestData extends Command | ||||
| 
 | ||||
|         // });
 | ||||
|         $client = Client::factory()->create([ | ||||
|                 'user_id' => $user->id, | ||||
|                 'company_id' => $company->id, | ||||
|             ]); | ||||
| 
 | ||||
|             'user_id' => $user->id, | ||||
|             'company_id' => $company->id, | ||||
|         ]); | ||||
| 
 | ||||
|         Document::factory()->count(50)->create([ | ||||
|                 'user_id' => $user->id, | ||||
|                 'company_id' => $company->id, | ||||
|                 'documentable_type' => Client::class, | ||||
|                 'documentable_id' => $client->id | ||||
|             ]); | ||||
|             'user_id' => $user->id, | ||||
|             'company_id' => $company->id, | ||||
|             'documentable_type' => Client::class, | ||||
|             'documentable_id' => $client->id, | ||||
|         ]); | ||||
| 
 | ||||
|         ClientContact::factory()->create([ | ||||
|                     'user_id' => $user->id, | ||||
|                     'client_id' => $client->id, | ||||
|                     'company_id' => $company->id, | ||||
|                     'is_primary' => 1, | ||||
|                 ]); | ||||
|             'user_id' => $user->id, | ||||
|             'client_id' => $client->id, | ||||
|             'company_id' => $company->id, | ||||
|             'is_primary' => 1, | ||||
|         ]); | ||||
| 
 | ||||
|         ClientContact::factory()->count(rand(1, 5))->create([ | ||||
|                     'user_id' => $user->id, | ||||
|                     'client_id' => $client->id, | ||||
|                     'company_id' => $company->id, | ||||
|                 ]); | ||||
|             'user_id' => $user->id, | ||||
|             'client_id' => $client->id, | ||||
|             'company_id' => $company->id, | ||||
|         ]); | ||||
| 
 | ||||
|         $client->number = $this->getNextClientNumber($client); | ||||
| 
 | ||||
| @ -422,70 +424,69 @@ class CreateTestData extends Command | ||||
|     private function createExpense($client) | ||||
|     { | ||||
|         Expense::factory()->count(rand(1, 5))->create([ | ||||
|                 'user_id' => $client->user->id, | ||||
|                 'client_id' => $client->id, | ||||
|                 'company_id' => $client->company->id, | ||||
|             ]); | ||||
|             'user_id' => $client->user->id, | ||||
|             'client_id' => $client->id, | ||||
|             'company_id' => $client->company->id, | ||||
|         ]); | ||||
|     } | ||||
| 
 | ||||
|     private function createVendor($client) | ||||
|     { | ||||
|         $vendor = Vendor::factory()->create([ | ||||
|                 'user_id' => $client->user->id, | ||||
|                 'company_id' => $client->company->id, | ||||
|             ]); | ||||
|             'user_id' => $client->user->id, | ||||
|             'company_id' => $client->company->id, | ||||
|         ]); | ||||
| 
 | ||||
|         Document::factory()->count(50)->create([ | ||||
|                 'user_id' => $client->user->id, | ||||
|                 'company_id' => $client->company_id, | ||||
|                 'documentable_type' => Vendor::class, | ||||
|                 'documentable_id' => $vendor->id | ||||
|             ]); | ||||
|             'user_id' => $client->user->id, | ||||
|             'company_id' => $client->company_id, | ||||
|             'documentable_type' => Vendor::class, | ||||
|             'documentable_id' => $vendor->id, | ||||
|         ]); | ||||
| 
 | ||||
|         VendorContact::factory()->create([ | ||||
|                 'user_id' => $client->user->id, | ||||
|                 'vendor_id' => $vendor->id, | ||||
|                 'company_id' => $client->company->id, | ||||
|                 'is_primary' => 1, | ||||
|             ]); | ||||
|             'user_id' => $client->user->id, | ||||
|             'vendor_id' => $vendor->id, | ||||
|             'company_id' => $client->company->id, | ||||
|             'is_primary' => 1, | ||||
|         ]); | ||||
| 
 | ||||
|         VendorContact::factory()->count(rand(1, 5))->create([ | ||||
|                 'user_id' => $client->user->id, | ||||
|                 'vendor_id' => $vendor->id, | ||||
|                 'company_id' => $client->company->id, | ||||
|                 'is_primary' => 0, | ||||
|             ]); | ||||
|             'user_id' => $client->user->id, | ||||
|             'vendor_id' => $vendor->id, | ||||
|             'company_id' => $client->company->id, | ||||
|             'is_primary' => 0, | ||||
|         ]); | ||||
|     } | ||||
| 
 | ||||
|     private function createTask($client) | ||||
|     { | ||||
|         $vendor = Task::factory()->create([ | ||||
|                 'user_id' => $client->user->id, | ||||
|                 'company_id' => $client->company->id, | ||||
|             ]); | ||||
| 
 | ||||
|             'user_id' => $client->user->id, | ||||
|             'company_id' => $client->company->id, | ||||
|         ]); | ||||
| 
 | ||||
|         Document::factory()->count(5)->create([ | ||||
|                 'user_id' => $client->user->id, | ||||
|                 'company_id' => $client->company_id, | ||||
|                 'documentable_type' => Task::class, | ||||
|                 'documentable_id' => $vendor->id | ||||
|             ]); | ||||
|             'user_id' => $client->user->id, | ||||
|             'company_id' => $client->company_id, | ||||
|             'documentable_type' => Task::class, | ||||
|             'documentable_id' => $vendor->id, | ||||
|         ]); | ||||
|     } | ||||
| 
 | ||||
|     private function createProject($client) | ||||
|     { | ||||
|         $vendor = Project::factory()->create([ | ||||
|                 'user_id' => $client->user->id, | ||||
|                 'company_id' => $client->company->id, | ||||
|             ]); | ||||
|             'user_id' => $client->user->id, | ||||
|             'company_id' => $client->company->id, | ||||
|         ]); | ||||
| 
 | ||||
|             Document::factory()->count(5)->create([ | ||||
|                 'user_id' => $client->user->id, | ||||
|                 'company_id' => $client->company_id, | ||||
|                 'documentable_type' => Project::class, | ||||
|                 'documentable_id' => $vendor->id | ||||
|             ]); | ||||
|         Document::factory()->count(5)->create([ | ||||
|             'user_id' => $client->user->id, | ||||
|             'company_id' => $client->company_id, | ||||
|             'documentable_type' => Project::class, | ||||
|             'documentable_id' => $vendor->id, | ||||
|         ]); | ||||
|     } | ||||
| 
 | ||||
|     private function createInvoice($client) | ||||
| @ -516,7 +517,7 @@ class CreateTestData extends Command | ||||
|             $invoice->tax_rate3 = 5; | ||||
|         } | ||||
| 
 | ||||
|         $invoice->custom_value1 = $faker->date; | ||||
|         $invoice->custom_value1 = $faker->date(); | ||||
|         $invoice->custom_value2 = rand(0, 1) ? 'yes' : 'no'; | ||||
| 
 | ||||
|         $invoice->save(); | ||||
| @ -537,16 +538,15 @@ class CreateTestData extends Command | ||||
|             $invoice = $invoice->service()->markPaid()->save(); | ||||
|         } | ||||
| 
 | ||||
|             Document::factory()->count(5)->create([ | ||||
|                 'user_id' => $invoice->user->id, | ||||
|                 'company_id' => $invoice->company_id, | ||||
|                 'documentable_type' => Invoice::class, | ||||
|                 'documentable_id' => $invoice->id | ||||
|             ]); | ||||
|         Document::factory()->count(5)->create([ | ||||
|             'user_id' => $invoice->user->id, | ||||
|             'company_id' => $invoice->company_id, | ||||
|             'documentable_type' => Invoice::class, | ||||
|             'documentable_id' => $invoice->id, | ||||
|         ]); | ||||
| 
 | ||||
|         RecurringInvoice::factory()->create(['user_id' => $invoice->user->id, 'company_id' => $invoice->company->id, 'client_id' => $invoice->client_id]); | ||||
| 
 | ||||
| 
 | ||||
|         event(new InvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars())); | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -73,8 +73,9 @@ class DemoMode extends Command | ||||
|     { | ||||
|         set_time_limit(0); | ||||
| 
 | ||||
|         if(config('ninja.is_docker')) | ||||
|         if (config('ninja.is_docker')) { | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         $this->invoice_repo = new InvoiceRepository(); | ||||
| 
 | ||||
| @ -111,9 +112,9 @@ class DemoMode extends Command | ||||
|         $this->info('Seeding Random Data'); | ||||
|         $this->createSmallAccount(); | ||||
| 
 | ||||
|         VersionCheck::dispatchNow(); | ||||
|         VersionCheck::dispatchSync(); | ||||
| 
 | ||||
|         CompanySizeCheck::dispatchNow(); | ||||
|         CompanySizeCheck::dispatchSync(); | ||||
|     } | ||||
| 
 | ||||
|     private function createSmallAccount() | ||||
| @ -136,15 +137,15 @@ class DemoMode extends Command | ||||
| 
 | ||||
|         $settings = $company->settings; | ||||
| 
 | ||||
|         $settings->name = $faker->company; | ||||
|         $settings->address1 = $faker->buildingNumber; | ||||
|         $settings->address2 = $faker->streetAddress; | ||||
|         $settings->city = $faker->city; | ||||
|         $settings->state = $faker->state; | ||||
|         $settings->postal_code = $faker->postcode; | ||||
|         $settings->website = $faker->url; | ||||
|         $settings->name = $faker->company(); | ||||
|         $settings->address1 = $faker->buildingNumber(); | ||||
|         $settings->address2 = $faker->streetAddress(); | ||||
|         $settings->city = $faker->city(); | ||||
|         $settings->state = $faker->state(); | ||||
|         $settings->postal_code = $faker->postcode(); | ||||
|         $settings->website = $faker->url(); | ||||
|         $settings->vat_number = (string) $faker->numberBetween(123456789, 987654321); | ||||
|         $settings->phone = (string) $faker->phoneNumber; | ||||
|         $settings->phone = (string) $faker->phoneNumber(); | ||||
| 
 | ||||
|         $company->settings = $settings; | ||||
|         $company->save(); | ||||
| @ -163,8 +164,8 @@ class DemoMode extends Command | ||||
|             ]); | ||||
|         } | ||||
| 
 | ||||
|         CreateCompanyPaymentTerms::dispatchNow($company, $user); | ||||
|         CreateCompanyTaskStatuses::dispatchNow($company, $user); | ||||
|         CreateCompanyPaymentTerms::dispatchSync($company, $user); | ||||
|         CreateCompanyTaskStatuses::dispatchSync($company, $user); | ||||
| 
 | ||||
|         $company_token = new CompanyToken; | ||||
|         $company_token->user_id = $user->id; | ||||
| @ -182,7 +183,7 @@ class DemoMode extends Command | ||||
|             'is_admin' => 1, | ||||
|             'is_locked' => 0, | ||||
|             'notifications' => CompanySettings::notificationDefaults(), | ||||
|            // 'permissions' => '',
 | ||||
|             // 'permissions' => '',
 | ||||
|             'settings' => null, | ||||
|         ]); | ||||
| 
 | ||||
| @ -217,9 +218,9 @@ class DemoMode extends Command | ||||
|         } | ||||
| 
 | ||||
|         Product::factory()->count(50)->create([ | ||||
|                 'user_id' => $user->id, | ||||
|                 'company_id' => $company->id, | ||||
|             ]); | ||||
|             'user_id' => $user->id, | ||||
|             'company_id' => $company->id, | ||||
|         ]); | ||||
| 
 | ||||
|         $this->info('Creating '.$this->count.' clients'); | ||||
| 
 | ||||
| @ -265,22 +266,22 @@ class DemoMode extends Command | ||||
| 
 | ||||
|         // });
 | ||||
|         $client = Client::factory()->create([ | ||||
|                 'user_id' => $user->id, | ||||
|                 'company_id' => $company->id, | ||||
|             ]); | ||||
|             'user_id' => $user->id, | ||||
|             'company_id' => $company->id, | ||||
|         ]); | ||||
| 
 | ||||
|         ClientContact::factory()->create([ | ||||
|                     'user_id' => $user->id, | ||||
|                     'client_id' => $client->id, | ||||
|                     'company_id' => $company->id, | ||||
|                     'is_primary' => 1, | ||||
|                 ]); | ||||
|             'user_id' => $user->id, | ||||
|             'client_id' => $client->id, | ||||
|             'company_id' => $company->id, | ||||
|             'is_primary' => 1, | ||||
|         ]); | ||||
| 
 | ||||
|         ClientContact::factory()->count(rand(1, 5))->create([ | ||||
|                     'user_id' => $user->id, | ||||
|                     'client_id' => $client->id, | ||||
|                     'company_id' => $company->id, | ||||
|                 ]); | ||||
|             'user_id' => $user->id, | ||||
|             'client_id' => $client->id, | ||||
|             'company_id' => $company->id, | ||||
|         ]); | ||||
| 
 | ||||
|         $client->number = $this->getNextClientNumber($client); | ||||
| 
 | ||||
| @ -299,41 +300,37 @@ class DemoMode extends Command | ||||
|     private function createExpense($client) | ||||
|     { | ||||
|         Expense::factory()->count(rand(1, 5))->create([ | ||||
|                 'user_id' => $client->user_id, | ||||
|                 'client_id' => $client->id, | ||||
|                 'company_id' => $client->company_id, | ||||
|             ]); | ||||
| 
 | ||||
|         Expense::all()->each(function ($expense){ | ||||
|             'user_id' => $client->user_id, | ||||
|             'client_id' => $client->id, | ||||
|             'company_id' => $client->company_id, | ||||
|         ]); | ||||
| 
 | ||||
|         Expense::all()->each(function ($expense) { | ||||
|             $expense->number = $this->getNextExpenseNumber($expense); | ||||
|             $expense->save(); | ||||
| 
 | ||||
|         }); | ||||
|          | ||||
|     } | ||||
| 
 | ||||
|     private function createVendor($client, $assigned_user_id = null) | ||||
|     { | ||||
|         $vendor = Vendor::factory()->create([ | ||||
|                 'user_id' => $client->user_id, | ||||
|                 'company_id' => $client->company_id, | ||||
|             ]); | ||||
|             'user_id' => $client->user_id, | ||||
|             'company_id' => $client->company_id, | ||||
|         ]); | ||||
| 
 | ||||
|         VendorContact::factory()->create([ | ||||
|                 'user_id' => $client->user->id, | ||||
|                 'vendor_id' => $vendor->id, | ||||
|                 'company_id' => $client->company_id, | ||||
|                 'is_primary' => 1, | ||||
|             ]); | ||||
|             'user_id' => $client->user->id, | ||||
|             'vendor_id' => $vendor->id, | ||||
|             'company_id' => $client->company_id, | ||||
|             'is_primary' => 1, | ||||
|         ]); | ||||
| 
 | ||||
|         VendorContact::factory()->count(rand(1, 5))->create([ | ||||
|                 'user_id' => $client->user->id, | ||||
|                 'vendor_id' => $vendor->id, | ||||
|                 'company_id' => $client->company_id, | ||||
|                 'is_primary' => 0, | ||||
|             ]); | ||||
| 
 | ||||
|             'user_id' => $client->user->id, | ||||
|             'vendor_id' => $vendor->id, | ||||
|             'company_id' => $client->company_id, | ||||
|             'is_primary' => 0, | ||||
|         ]); | ||||
| 
 | ||||
|         $vendor->number = $this->getNextVendorNumber($vendor); | ||||
|         $vendor->save(); | ||||
| @ -342,25 +339,24 @@ class DemoMode extends Command | ||||
|     private function createTask($client, $assigned_user_id = null) | ||||
|     { | ||||
|         $task = Task::factory()->create([ | ||||
|                 'user_id' => $client->user->id, | ||||
|                 'company_id' => $client->company_id, | ||||
|                 'client_id' => $client->id | ||||
|             ]); | ||||
|             'user_id' => $client->user->id, | ||||
|             'company_id' => $client->company_id, | ||||
|             'client_id' => $client->id, | ||||
|         ]); | ||||
| 
 | ||||
|         $task->status_id = TaskStatus::all()->random()->id; | ||||
| 
 | ||||
|         $task->number = $this->getNextTaskNumber($task); | ||||
|         $task->save(); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private function createProject($client, $assigned_user_id = null) | ||||
|     { | ||||
|         $project = Project::factory()->create([ | ||||
|                 'user_id' => $client->user->id, | ||||
|                 'company_id' => $client->company_id, | ||||
|                 'client_id' => $client->id, | ||||
|             ]); | ||||
|             'user_id' => $client->user->id, | ||||
|             'company_id' => $client->company_id, | ||||
|             'client_id' => $client->id, | ||||
|         ]); | ||||
| 
 | ||||
|         $project->number = $this->getNextProjectNumber($project); | ||||
|         $project->save(); | ||||
| @ -399,7 +395,7 @@ class DemoMode extends Command | ||||
|         //     $invoice->tax_rate3 = 5;
 | ||||
|         // }
 | ||||
| 
 | ||||
|         // $invoice->custom_value1 = $faker->date;
 | ||||
|         // $invoice->custom_value1 = $faker->date();
 | ||||
|         // $invoice->custom_value2 = rand(0, 1) ? 'yes' : 'no';
 | ||||
| 
 | ||||
|         $invoice->save(); | ||||
| @ -466,7 +462,7 @@ class DemoMode extends Command | ||||
|         //     $invoice->tax_rate3 = 5;
 | ||||
|         // }
 | ||||
| 
 | ||||
|         // $invoice->custom_value1 = $faker->date;
 | ||||
|         // $invoice->custom_value1 = $faker->date();
 | ||||
|         // $invoice->custom_value2 = rand(0, 1) ? 'yes' : 'no';
 | ||||
| 
 | ||||
|         $invoice->save(); | ||||
|  | ||||
| @ -64,11 +64,8 @@ class DesignUpdate extends Command | ||||
|                 $this->handleOnDb($db); | ||||
|             } | ||||
| 
 | ||||
|         MultiDB::setDB($current_db); | ||||
|          | ||||
|             MultiDB::setDB($current_db); | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private function handleOnDb() | ||||
|  | ||||
| @ -71,26 +71,27 @@ class HostedMigrations extends Command | ||||
|     public function handle() | ||||
|     { | ||||
|         $this->buildCache(); | ||||
|      | ||||
|         if(!MultiDB::userFindAndSetDb($this->option('email'))){ | ||||
|             $this->info("Could not find a user with that email address"); | ||||
| 
 | ||||
|         if (! MultiDB::userFindAndSetDb($this->option('email'))) { | ||||
|             $this->info('Could not find a user with that email address'); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         $user = User::where('email', $this->option('email'))->first(); | ||||
| 
 | ||||
|         if(!$user){ | ||||
|             $this->info("There was a problem getting the user, did you set the right DB?"); | ||||
|         if (! $user) { | ||||
|             $this->info('There was a problem getting the user, did you set the right DB?'); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         $path = public_path('storage/migrations/import'); | ||||
|          | ||||
| 
 | ||||
|         $directory = new DirectoryIterator($path); | ||||
| 
 | ||||
|         foreach ($directory as $file) { | ||||
|             if ($file->getExtension() === 'zip') { | ||||
| 
 | ||||
|                 $company = $user->companies()->first(); | ||||
| 
 | ||||
|                 $this->info('Started processing: '.$file->getBasename().' at '.now()); | ||||
| @ -104,14 +105,13 @@ class HostedMigrations extends Command | ||||
|                     } | ||||
| 
 | ||||
|                     $filename = pathinfo($file->getRealPath(), PATHINFO_FILENAME); | ||||
|                          | ||||
| 
 | ||||
|                     $zip->extractTo(public_path("storage/migrations/{$filename}")); | ||||
|                     $zip->close(); | ||||
| 
 | ||||
|                     $import_file = public_path("storage/migrations/$filename/migration.json"); | ||||
| 
 | ||||
|                     Import::dispatch($import_file, $user->companies()->first(), $user); | ||||
| 
 | ||||
|                 } catch (NonExistingMigrationFile | ProcessingMigrationArchiveFailed | ResourceNotAvailableForMigration | MigrationValidatorFailed | ResourceDependencyMissing $e) { | ||||
|                     \Mail::to($this->user)->send(new MigrationFailed($e, $e->getMessage())); | ||||
| 
 | ||||
| @ -122,5 +122,4 @@ class HostedMigrations extends Command | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -41,21 +41,16 @@ class HostedUsers extends Command | ||||
|      */ | ||||
|     public function handle() | ||||
|     { | ||||
| 
 | ||||
|         Company::on('db-ninja-01')->each(function ($company){ | ||||
| 
 | ||||
|             if(Ninja::isHosted()) | ||||
|                 \Modules\Admin\Jobs\Account\NinjaUser::dispatchNow([], $company); | ||||
|          | ||||
|         Company::on('db-ninja-01')->each(function ($company) { | ||||
|             if (Ninja::isHosted()) { | ||||
|                 \Modules\Admin\Jobs\Account\NinjaUser::dispatchSync([], $company); | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
|         Company::on('db-ninja-02')->each(function ($company){ | ||||
|              | ||||
|             if(Ninja::isHosted()) | ||||
|                 \Modules\Admin\Jobs\Account\NinjaUser::dispatchNow([], $company); | ||||
| 
 | ||||
|         Company::on('db-ninja-02')->each(function ($company) { | ||||
|             if (Ninja::isHosted()) { | ||||
|                 \Modules\Admin\Jobs\Account\NinjaUser::dispatchSync([], $company); | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -77,9 +77,9 @@ class ImportMigrations extends Command | ||||
|     public function handle() | ||||
|     { | ||||
|         $this->buildCache(); | ||||
|      | ||||
| 
 | ||||
|         $path = $this->option('path') ?? public_path('storage/migrations/import'); | ||||
|          | ||||
| 
 | ||||
|         $directory = new DirectoryIterator($path); | ||||
| 
 | ||||
|         foreach ($directory as $file) { | ||||
| @ -98,7 +98,7 @@ class ImportMigrations extends Command | ||||
|                     } | ||||
| 
 | ||||
|                     $filename = pathinfo($file->getRealPath(), PATHINFO_FILENAME); | ||||
|                          | ||||
| 
 | ||||
|                     $zip->extractTo(public_path("storage/migrations/{$filename}")); | ||||
|                     $zip->close(); | ||||
| 
 | ||||
| @ -124,7 +124,7 @@ class ImportMigrations extends Command | ||||
| 
 | ||||
|         $user = User::factory()->create([ | ||||
|             'account_id' => $account->id, | ||||
|             'email' => Str::random(10) . "@example.com", | ||||
|             'email' => Str::random(10).'@example.com', | ||||
|             'confirmation_code' => $this->createDbHash($company->db), | ||||
|         ]); | ||||
| 
 | ||||
| @ -137,7 +137,7 @@ class ImportMigrations extends Command | ||||
|             'name' => 'First token', | ||||
|             'token' => Str::random(64), | ||||
|         ]); | ||||
|          | ||||
| 
 | ||||
|         $user->companies()->attach($company->id, [ | ||||
|             'account_id' => $account->id, | ||||
|             'is_owner' => 1, | ||||
|  | ||||
| @ -23,7 +23,6 @@ class MobileLocalization extends Command | ||||
|      */ | ||||
|     protected $description = 'Generate mobile localization resources'; | ||||
| 
 | ||||
| 
 | ||||
|     /** | ||||
|      * Create a new command instance. | ||||
|      * | ||||
| @ -83,9 +82,9 @@ class MobileLocalization extends Command | ||||
|                     $text = $resources->$key; | ||||
|                 } | ||||
| 
 | ||||
|                 $text = str_replace(array('<b>', '</b>'), '', $text); | ||||
|                 $text = str_replace(array('<i>', '</i>'), '', $text); | ||||
|                 $text = str_replace(array('<strong>', '</strong>'), '', $text); | ||||
|                 $text = str_replace(['<b>', '</b>'], '', $text); | ||||
|                 $text = str_replace(['<i>', '</i>'], '', $text); | ||||
|                 $text = str_replace(['<strong>', '</strong>'], '', $text); | ||||
| 
 | ||||
|                 echo "'$key': '$text',\n"; | ||||
|             } | ||||
| @ -103,11 +102,11 @@ class MobileLocalization extends Command | ||||
|         $end = strpos($data, '},', $start); | ||||
|         $data = substr($data, $start, $end - $start - 5); | ||||
| 
 | ||||
|         $data = str_replace("\n", "", $data); | ||||
|         $data = str_replace("\"", "\'", $data); | ||||
|         $data = str_replace("'", "\"", $data); | ||||
|         $data = str_replace("\n", '', $data); | ||||
|         $data = str_replace('"', "\'", $data); | ||||
|         $data = str_replace("'", '"', $data); | ||||
| 
 | ||||
|         return json_decode('{' . rtrim($data, ',') . '}'); | ||||
|         return json_decode('{'.rtrim($data, ',').'}'); | ||||
|     } | ||||
| 
 | ||||
|     protected function getOptions() | ||||
| @ -116,5 +115,4 @@ class MobileLocalization extends Command | ||||
|             ['type', null, InputOption::VALUE_OPTIONAL, 'Type', null], | ||||
|         ]; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -52,15 +52,10 @@ class ParallelCheckData extends Command | ||||
| 
 | ||||
|     public function handle() | ||||
|     { | ||||
|      | ||||
|     	$hash = Str::random(32); | ||||
| 
 | ||||
|     	Company::cursor()->each(function ($company) use ($hash){ | ||||
| 
 | ||||
|     		CheckCompanyData::dispatch($company, $hash)->onQueue('checkdata'); | ||||
|     		 | ||||
|     	}); | ||||
|         $hash = Str::random(32); | ||||
| 
 | ||||
|         Company::cursor()->each(function ($company) use ($hash) { | ||||
|             CheckCompanyData::dispatch($company, $hash)->onQueue('checkdata'); | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| } | ||||
|  | ||||
| @ -50,24 +50,22 @@ class PostUpdate extends Command | ||||
|             info("I wasn't able to migrate the data."); | ||||
|         } | ||||
| 
 | ||||
|         info("finished migrating"); | ||||
|         info('finished migrating'); | ||||
| 
 | ||||
|         $output = []; | ||||
| 
 | ||||
|         // exec('vendor/bin/composer install --no-dev -o', $output);
 | ||||
| 
 | ||||
|         info(print_r($output,1)); | ||||
|         info("finished running composer install "); | ||||
|         info(print_r($output, 1)); | ||||
|         info('finished running composer install '); | ||||
| 
 | ||||
|         try { | ||||
| 
 | ||||
|             Artisan::call('optimize'); | ||||
| 
 | ||||
|         } catch (\Exception $e) { | ||||
|             info("I wasn't able to optimize."); | ||||
|         } | ||||
| 
 | ||||
|         info("optimized"); | ||||
|         info('optimized'); | ||||
| 
 | ||||
|         try { | ||||
|             Artisan::call('view:clear'); | ||||
| @ -75,7 +73,7 @@ class PostUpdate extends Command | ||||
|             info("I wasn't able to clear the views."); | ||||
|         } | ||||
| 
 | ||||
|         info("view cleared"); | ||||
|         info('view cleared'); | ||||
| 
 | ||||
|         try { | ||||
|             Artisan::call('queue:restart'); | ||||
| @ -83,11 +81,10 @@ class PostUpdate extends Command | ||||
|             info("I wasn't able to restart the queue."); | ||||
|         } | ||||
| 
 | ||||
|         info("queue restarted"); | ||||
|         info('queue restarted'); | ||||
| 
 | ||||
|         VersionCheck::dispatch(); | ||||
| 
 | ||||
|         info("Sent for version check"); | ||||
| 
 | ||||
|         info('Sent for version check'); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -56,33 +56,19 @@ class ReactBuilder extends Command | ||||
|         $directoryIterator = new \RecursiveDirectoryIterator(public_path('react'), \RecursiveDirectoryIterator::SKIP_DOTS); | ||||
| 
 | ||||
|         foreach (new \RecursiveIteratorIterator($directoryIterator) as $file) { | ||||
| 
 | ||||
|           if(str_contains($file->getFileName(), '.js')) { | ||||
| 
 | ||||
|             if(str_contains($file->getFileName(), 'index.')){             | ||||
| 
 | ||||
|                 $includes .= '<script type="module" crossorigin src="/react/' . $file->getFileName() . '"></script>'."\n"; | ||||
| 
 | ||||
|             } | ||||
|             else{ | ||||
| 
 | ||||
|                 $includes .= '<link rel="modulepreload" href="/react/' . $file->getFileName() . '">'."\n"; | ||||
|             if (str_contains($file->getFileName(), '.js')) { | ||||
|                 if (str_contains($file->getFileName(), 'index.')) { | ||||
|                     $includes .= '<script type="module" crossorigin src="/react/'.$file->getFileName().'"></script>'."\n"; | ||||
|                 } else { | ||||
|                     $includes .= '<link rel="modulepreload" href="/react/'.$file->getFileName().'">'."\n"; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|           } | ||||
| 
 | ||||
| 
 | ||||
|           if(str_contains($file->getFileName(), '.css')) { | ||||
| 
 | ||||
|             $includes .= '<link rel="stylesheet" href="/react/' . $file->getFileName() . '">'."\n"; | ||||
| 
 | ||||
|           } | ||||
|    | ||||
|             if (str_contains($file->getFileName(), '.css')) { | ||||
|                 $includes .= '<link rel="stylesheet" href="/react/'.$file->getFileName().'">'."\n"; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         file_put_contents(resource_path('views/react/head.blade.php'), $includes); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -47,6 +47,6 @@ class RecurringCommand extends Command | ||||
|      */ | ||||
|     public function handle() | ||||
|     { | ||||
|         RecurringInvoicesCron::dispatchNow(); | ||||
|         RecurringInvoicesCron::dispatchSync(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -42,10 +42,10 @@ class S3Cleanup extends Command | ||||
|      */ | ||||
|     public function handle() | ||||
|     { | ||||
| 
 | ||||
|         if(!Ninja::isHosted()) | ||||
|         if (! Ninja::isHosted()) { | ||||
|             return; | ||||
|          | ||||
|         } | ||||
| 
 | ||||
|         $c1 = Company::on('db-ninja-01')->pluck('company_key'); | ||||
|         $c2 = Company::on('db-ninja-02')->pluck('company_key'); | ||||
| 
 | ||||
| @ -53,23 +53,20 @@ class S3Cleanup extends Command | ||||
| 
 | ||||
|         $directories = Storage::disk(config('filesystems.default'))->directories(); | ||||
| 
 | ||||
|         $this->LogMessage("Disk Cleanup"); | ||||
|         $this->LogMessage('Disk Cleanup'); | ||||
| 
 | ||||
|             foreach($directories as $dir) | ||||
|             { | ||||
|                 if(!in_array($dir, $merged)) | ||||
|                 { | ||||
|                     $this->logMessage("Deleting $dir"); | ||||
|         foreach ($directories as $dir) { | ||||
|             if (! in_array($dir, $merged)) { | ||||
|                 $this->logMessage("Deleting $dir"); | ||||
| 
 | ||||
|                     /* Ensure we are not deleting the root folder */ | ||||
|                     if(strlen($dir) > 1) | ||||
|                         Storage::disk(config('filesystems.default'))->deleteDirectory($dir); | ||||
|                      | ||||
|                 /* Ensure we are not deleting the root folder */ | ||||
|                 if (strlen($dir) > 1) { | ||||
|                     Storage::disk(config('filesystems.default'))->deleteDirectory($dir); | ||||
|                 } | ||||
|             }         | ||||
| 
 | ||||
|         $this->logMessage("exiting"); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         $this->logMessage('exiting'); | ||||
|     } | ||||
| 
 | ||||
|     private function logMessage($str) | ||||
|  | ||||
| @ -29,6 +29,7 @@ use Illuminate\Support\Facades\App; | ||||
| class SendRemindersCron extends Command | ||||
| { | ||||
|     use MakesReminders, MakesDates; | ||||
| 
 | ||||
|     /** | ||||
|      * The name and signature of the console command. | ||||
|      * | ||||
| @ -60,56 +61,49 @@ class SendRemindersCron extends Command | ||||
|      */ | ||||
|     public function handle() | ||||
|     { | ||||
| 
 | ||||
|         Invoice::where('next_send_date', '<=', now()->toDateTimeString()) | ||||
|                  ->whereNull('deleted_at') | ||||
|                  ->where('is_deleted', 0) | ||||
|                  ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) | ||||
|                  ->where('balance', '>', 0) | ||||
|                  ->whereHas('client', function ($query) { | ||||
|                      $query->where('is_deleted',0) | ||||
|                            ->where('deleted_at', NULL); | ||||
|                      $query->where('is_deleted', 0) | ||||
|                            ->where('deleted_at', null); | ||||
|                  }) | ||||
|                  ->whereHas('company', function ($query) { | ||||
|                      $query->where('is_disabled',0); | ||||
|                      $query->where('is_disabled', 0); | ||||
|                  }) | ||||
|                  ->with('invitations')->cursor()->each(function ($invoice) { | ||||
|                      if ($invoice->isPayable()) { | ||||
|                          $reminder_template = $invoice->calculateTemplate('invoice'); | ||||
|                          $invoice->service()->touchReminder($reminder_template)->save(); | ||||
|                          $invoice = $this->calcLateFee($invoice, $reminder_template); | ||||
| 
 | ||||
|             if ($invoice->isPayable()) { | ||||
|                 $reminder_template = $invoice->calculateTemplate('invoice'); | ||||
|                 $invoice->service()->touchReminder($reminder_template)->save(); | ||||
|                 $invoice = $this->calcLateFee($invoice, $reminder_template); | ||||
|                          //check if this reminder needs to be emailed
 | ||||
|                          if (in_array($reminder_template, ['reminder1', 'reminder2', 'reminder3']) && $invoice->client->getSetting('enable_'.$reminder_template)) { | ||||
|                              $invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) { | ||||
|                                  EmailEntity::dispatch($invitation, $invitation->company, $reminder_template); | ||||
|                                  nlog("Firing reminder email for invoice {$invoice->number}"); | ||||
|                              }); | ||||
| 
 | ||||
|                 //check if this reminder needs to be emailed
 | ||||
|                 if(in_array($reminder_template, ['reminder1','reminder2','reminder3']) && $invoice->client->getSetting("enable_".$reminder_template)) | ||||
|                 { | ||||
|                     $invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) { | ||||
|                         EmailEntity::dispatch($invitation, $invitation->company, $reminder_template); | ||||
|                         nlog("Firing reminder email for invoice {$invoice->number}"); | ||||
|                     }); | ||||
|                              if ($invoice->invitations->count() > 0) { | ||||
|                                  event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company, Ninja::eventVars(), $reminder_template)); | ||||
|                              } | ||||
|                          } | ||||
|                          $invoice->service()->setReminder()->save(); | ||||
|                      } else { | ||||
|                          $invoice->next_send_date = null; | ||||
|                          $invoice->save(); | ||||
|                      } | ||||
|                  }); | ||||
| 
 | ||||
|                     if ($invoice->invitations->count() > 0) { | ||||
|                         event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company, Ninja::eventVars(), $reminder_template)); | ||||
|                     } | ||||
|                 } | ||||
|                 $invoice->service()->setReminder()->save(); | ||||
|                  | ||||
|             } else { | ||||
|                 $invoice->next_send_date = null; | ||||
|                 $invoice->save(); | ||||
|             } | ||||
| 
 | ||||
|         }); | ||||
| 
 | ||||
| 
 | ||||
|        //  SendReminders::dispatchNow();
 | ||||
|         //  SendReminders::dispatchNow();
 | ||||
| 
 | ||||
|        // $this->webHookOverdueInvoices();
 | ||||
|        // $this->webHookExpiredQuotes();
 | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|  private function calcLateFee($invoice, $template) :Invoice | ||||
|     private function calcLateFee($invoice, $template) :Invoice | ||||
|     { | ||||
|         $late_fee_amount = 0; | ||||
|         $late_fee_percent = 0; | ||||
| @ -151,7 +145,6 @@ class SendRemindersCron extends Command | ||||
|      */ | ||||
|     private function setLateFee($invoice, $amount, $percent) :Invoice | ||||
|     { | ||||
| 
 | ||||
|         App::forgetInstance('translator'); | ||||
|         $t = app('translator'); | ||||
|         $t->replace(Ninja::transformTranslations($invoice->client->getMergedSettings())); | ||||
| @ -187,49 +180,20 @@ class SendRemindersCron extends Command | ||||
|         $invoice->calc()->getInvoice()->save(); | ||||
|         $invoice->fresh(); | ||||
|         $invoice->service()->deletePdf(); | ||||
|          | ||||
| 
 | ||||
|         /* Refresh the client here to ensure the balance is fresh */ | ||||
|         $client = $invoice->client; | ||||
|         $client = $client->fresh(); | ||||
| 
 | ||||
|         nlog("adjusting client balance and invoice balance by ". ($invoice->balance - $temp_invoice_balance)); | ||||
|         nlog('adjusting client balance and invoice balance by '.($invoice->balance - $temp_invoice_balance)); | ||||
|         $client->service()->updateBalance($invoice->balance - $temp_invoice_balance)->save(); | ||||
|         $invoice->ledger()->updateInvoiceBalance($invoice->balance - $temp_invoice_balance, "Late Fee Adjustment for invoice {$invoice->number}"); | ||||
| 
 | ||||
|         return $invoice; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     private function webHookOverdueInvoices() | ||||
|     { | ||||
| 
 | ||||
| 
 | ||||
|         if (! config('ninja.db.multi_db_enabled')) { | ||||
|             $this->executeWebhooks(); | ||||
|         } else { | ||||
| @ -240,12 +204,10 @@ class SendRemindersCron extends Command | ||||
|                 $this->executeWebhooks(); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private function webHookExpiredQuotes() | ||||
|     { | ||||
|          | ||||
|     } | ||||
| 
 | ||||
|     private function executeWebhooks() | ||||
| @ -255,21 +217,18 @@ class SendRemindersCron extends Command | ||||
|                           ->where('balance', '>', 0) | ||||
|                           ->whereDate('due_date', '<=', now()->subDays(1)->startOfDay()) | ||||
|                           ->cursor(); | ||||
|      | ||||
| 
 | ||||
|         $invoices->each(function ($invoice) { | ||||
|             WebhookHandler::dispatch(Webhook::EVENT_LATE_INVOICE, $invoice, $invoice->company); | ||||
|              | ||||
|         }); | ||||
| 
 | ||||
|         $quotes = Quote::where('is_deleted', 0) | ||||
|                           ->where('status_id', Quote::STATUS_SENT) | ||||
|                           ->whereDate('due_date', '<=', now()->subDays(1)->startOfDay()) | ||||
|                           ->cursor(); | ||||
|      | ||||
| 
 | ||||
|         $quotes->each(function ($quote) { | ||||
|             WebhookHandler::dispatch(Webhook::EVENT_EXPIRED_QUOTE, $quote, $quote->company); | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -70,7 +70,7 @@ class SendTestEmails extends Command | ||||
|         $user = User::factory()->create([ | ||||
|             'account_id' => $account->id, | ||||
|             'confirmation_code' => '123', | ||||
|             'email' => $faker->safeEmail, | ||||
|             'email' => $faker->safeEmail(), | ||||
|             'first_name' => 'John', | ||||
|             'last_name' => 'Doe', | ||||
|         ]); | ||||
| @ -96,6 +96,6 @@ class SendTestEmails extends Command | ||||
|         $nmo->settings = $user->account->companies()->first()->settings; | ||||
|         $nmo->to_user = $user; | ||||
| 
 | ||||
|         NinjaMailerJob::dispatchNow($nmo); | ||||
|         NinjaMailerJob::dispatchSync($nmo); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -40,25 +40,17 @@ class SubdomainFill extends Command | ||||
|      */ | ||||
|     public function handle() | ||||
|     { | ||||
| 
 | ||||
|         $c1 = Company::on('db-ninja-01')->whereNull('subdomain')->orWhere('subdomain', '')->get(); | ||||
|         $c2 = Company::on('db-ninja-02')->whereNull('subdomain')->orWhere('subdomain', '')->get(); | ||||
| 
 | ||||
| 
 | ||||
|         $c1->each(function ($company){ | ||||
| 
 | ||||
|         $c1->each(function ($company) { | ||||
|             $company->subdomain = MultiDB::randomSubdomainGenerator(); | ||||
|             $company->save(); | ||||
| 
 | ||||
|         }); | ||||
| 
 | ||||
|         $c2->each(function ($company){ | ||||
| 
 | ||||
|         $c2->each(function ($company) { | ||||
|             $company->subdomain = MultiDB::randomSubdomainGenerator(); | ||||
|             $company->save(); | ||||
| 
 | ||||
|         }); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -69,8 +69,9 @@ class TranslationsExport extends Command | ||||
|         'sv', | ||||
|         'th', | ||||
|         'tr_TR', | ||||
|         'zh_TW' | ||||
|         'zh_TW', | ||||
|     ]; | ||||
| 
 | ||||
|     /** | ||||
|      * Create a new command instance. | ||||
|      * | ||||
| @ -88,19 +89,14 @@ class TranslationsExport extends Command | ||||
|      */ | ||||
|     public function handle() | ||||
|     { | ||||
| 
 | ||||
|         Storage::makeDirectory(storage_path('lang')); | ||||
| 
 | ||||
|         foreach($this->langs as $lang) | ||||
|         { | ||||
|         foreach ($this->langs as $lang) { | ||||
|             Storage::makeDirectory(storage_path("lang/{$lang}")); | ||||
| 
 | ||||
|             $translations = Lang::getLoader()->load($lang,'texts'); | ||||
|             $translations = Lang::getLoader()->load($lang, 'texts'); | ||||
| 
 | ||||
|             Storage::put(storage_path("lang/{$lang}/{$lang}.json"), json_encode(Arr::dot($translations), JSON_UNESCAPED_UNICODE)); | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -43,7 +43,6 @@ class TypeCheck extends Command | ||||
| 
 | ||||
|     protected $log = ''; | ||||
| 
 | ||||
| 
 | ||||
|     /** | ||||
|      * Create a new command instance. | ||||
|      * | ||||
| @ -65,91 +64,74 @@ class TypeCheck extends Command | ||||
| 
 | ||||
|         $current_db = config('database.default'); | ||||
| 
 | ||||
|         if($this->option('all')) | ||||
|         { | ||||
|         if ($this->option('all')) { | ||||
|             if (! config('ninja.db.multi_db_enabled')) { | ||||
|                     $this->checkAll(); | ||||
|                 $this->checkAll(); | ||||
|             } else { | ||||
| 
 | ||||
|                 foreach (MultiDB::$dbs as $db)  | ||||
|                 { | ||||
|                 foreach (MultiDB::$dbs as $db) { | ||||
|                     MultiDB::setDB($db); | ||||
| 
 | ||||
|                     $this->checkAll(); | ||||
|                 } | ||||
| 
 | ||||
|                 MultiDB::setDB($current_db); | ||||
|              | ||||
|             } | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         if($this->option('client_id')) | ||||
|         { | ||||
|         if ($this->option('client_id')) { | ||||
|             $client = MultiDB::findAndSetDbByClientId($this->option('client_id')); | ||||
| 
 | ||||
|             if($client) | ||||
|             if ($client) { | ||||
|                 $this->checkClient($client); | ||||
|             else | ||||
|             } else { | ||||
|                 $this->logMessage(date('Y-m-d h:i:s').' Could not find this client'); | ||||
| 
 | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         if($this->option('company_id')) | ||||
|         { | ||||
|         if ($this->option('company_id')) { | ||||
|             $company = MultiDB::findAndSetDbByCompanyId($this->option('company_id')); | ||||
| 
 | ||||
| 
 | ||||
|             if($company) | ||||
|             if ($company) { | ||||
|                 $this->checkCompany($company); | ||||
|             else | ||||
|             } else { | ||||
|                 $this->logMessage(date('Y-m-d h:i:s').' Could not find this company'); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     private function checkClient($client) | ||||
|     { | ||||
|         $this->logMessage(date('Y-m-d h:i:s').' Checking Client => ' . $client->present()->name(). " " . $client->id); | ||||
| 
 | ||||
| 
 | ||||
|             $entity_settings = $this->checkSettingType($client->settings); | ||||
|             $entity_settings->md5 = md5(time()); | ||||
|             $client->settings = $entity_settings; | ||||
|             $client->save(); | ||||
|         $this->logMessage(date('Y-m-d h:i:s').' Checking Client => '.$client->present()->name().' '.$client->id); | ||||
| 
 | ||||
|         $entity_settings = $this->checkSettingType($client->settings); | ||||
|         $entity_settings->md5 = md5(time()); | ||||
|         $client->settings = $entity_settings; | ||||
|         $client->save(); | ||||
|     } | ||||
| 
 | ||||
|     private function checkCompany($company) | ||||
|     { | ||||
|         $this->logMessage(date('Y-m-d h:i:s').' Checking Company => ' . $company->present()->name(). " " . $company->id); | ||||
| 
 | ||||
|             $company->saveSettings((array)$company->settings, $company); | ||||
|         $this->logMessage(date('Y-m-d h:i:s').' Checking Company => '.$company->present()->name().' '.$company->id); | ||||
| 
 | ||||
|         $company->saveSettings((array) $company->settings, $company); | ||||
|     } | ||||
| 
 | ||||
|     private function checkAll() | ||||
|     { | ||||
| 
 | ||||
|         $this->logMessage(date('Y-m-d h:i:s').' Checking all clients and companies.'); | ||||
| 
 | ||||
|         Client::withTrashed()->cursor()->each( function ($client) { | ||||
|         Client::withTrashed()->cursor()->each(function ($client) { | ||||
|             $this->logMessage("Checking client {$client->id}"); | ||||
|             $entity_settings = $this->checkSettingType($client->settings); | ||||
|             $entity_settings->md5 = md5(time()); | ||||
|             $client->settings = $entity_settings; | ||||
|             $client->save(); | ||||
|              | ||||
|         }); | ||||
| 
 | ||||
|         Company::cursor()->each( function ($company) { | ||||
|         Company::cursor()->each(function ($company) { | ||||
|             $this->logMessage("Checking company {$company->id}"); | ||||
|             $company->saveSettings($company->settings, $company); | ||||
|              | ||||
|         }); | ||||
| 
 | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private function logMessage($str) | ||||
| @ -159,4 +141,3 @@ class TypeCheck extends Command | ||||
|         $this->log .= $str."\n"; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -34,15 +34,6 @@ use Illuminate\Foundation\Console\Kernel as ConsoleKernel; | ||||
| 
 | ||||
| class Kernel extends ConsoleKernel | ||||
| { | ||||
|     /** | ||||
|      * The Artisan commands provided by your application. | ||||
|      * | ||||
|      * @var array | ||||
|      */ | ||||
|     protected $commands = [ | ||||
|         //
 | ||||
|     ]; | ||||
| 
 | ||||
|     /** | ||||
|      * Define the application's command schedule. | ||||
|      * | ||||
| @ -51,7 +42,6 @@ class Kernel extends ConsoleKernel | ||||
|      */ | ||||
|     protected function schedule(Schedule $schedule) | ||||
|     { | ||||
| 
 | ||||
|         $schedule->job(new VersionCheck)->daily(); | ||||
| 
 | ||||
|         $schedule->job(new DiskCleanup)->daily()->withoutOverlapping(); | ||||
| @ -78,17 +68,14 @@ class Kernel extends ConsoleKernel | ||||
| 
 | ||||
|         $schedule->job(new SystemMaintenance)->weekly()->withoutOverlapping(); | ||||
| 
 | ||||
|         if(Ninja::isSelfHost()) | ||||
|         { | ||||
|         if (Ninja::isSelfHost()) { | ||||
|             $schedule->call(function () { | ||||
|                 Account::whereNotNull('id')->update(['is_scheduler_running' => true]); | ||||
|             })->everyFiveMinutes(); | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         /* Run hosted specific jobs */ | ||||
|         if (Ninja::isHosted()) { | ||||
| 
 | ||||
|             $schedule->job(new AdjustEmailQuota)->dailyAt('23:30')->withoutOverlapping(); | ||||
| 
 | ||||
|             $schedule->job(new SendFailedEmails)->daily()->withoutOverlapping(); | ||||
| @ -98,17 +85,13 @@ class Kernel extends ConsoleKernel | ||||
|             $schedule->command('ninja:check-data --database=db-ninja-02')->dailyAt('02:05')->withoutOverlapping(); | ||||
| 
 | ||||
|             $schedule->command('ninja:s3-cleanup')->dailyAt('23:15')->withoutOverlapping(); | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         if (config('queue.default') == 'database' && Ninja::isSelfHost() && config('ninja.internal_queue_enabled') && !config('ninja.is_docker')) { | ||||
| 
 | ||||
|         if (config('queue.default') == 'database' && Ninja::isSelfHost() && config('ninja.internal_queue_enabled') && ! config('ninja.is_docker')) { | ||||
|             $schedule->command('queue:work database --stop-when-empty --memory=256')->everyMinute()->withoutOverlapping(); | ||||
| 
 | ||||
|             $schedule->command('queue:restart')->everyFiveMinutes()->withoutOverlapping(); | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
| @ -118,7 +101,7 @@ class Kernel extends ConsoleKernel | ||||
|      */ | ||||
|     protected function commands() | ||||
|     { | ||||
|         $this->load(__DIR__ . '/Commands'); | ||||
|         $this->load(__DIR__.'/Commands'); | ||||
| 
 | ||||
|         require base_path('routes/console.php'); | ||||
|     } | ||||
|  | ||||
| @ -53,7 +53,8 @@ class AccountPlatform extends GenericMixedMetric | ||||
| 
 | ||||
|     public $string_metric7 = 'ip_address'; | ||||
| 
 | ||||
|     public function __construct($string_metric5, $string_metric6, $string_metric7) { | ||||
|     public function __construct($string_metric5, $string_metric6, $string_metric7) | ||||
|     { | ||||
|         $this->string_metric5 = $string_metric5; | ||||
|         $this->string_metric6 = $string_metric6; | ||||
|         $this->string_metric7 = $string_metric7; | ||||
|  | ||||
| @ -52,6 +52,7 @@ class DbQuery extends GenericMixedMetric | ||||
|     public $string_metric6 = 'url'; | ||||
| 
 | ||||
|     public $string_metric7 = 'ip_address'; | ||||
| 
 | ||||
|     /** | ||||
|      * The counter | ||||
|      * set to 1. | ||||
| @ -62,7 +63,8 @@ class DbQuery extends GenericMixedMetric | ||||
| 
 | ||||
|     public $double_metric2 = 1; | ||||
| 
 | ||||
|     public function __construct($string_metric5, $string_metric6, $int_metric1, $double_metric2, $string_metric7) { | ||||
|     public function __construct($string_metric5, $string_metric6, $int_metric1, $double_metric2, $string_metric7) | ||||
|     { | ||||
|         $this->int_metric1 = $int_metric1; | ||||
|         $this->string_metric5 = $string_metric5; | ||||
|         $this->string_metric6 = $string_metric6; | ||||
|  | ||||
| @ -71,7 +71,8 @@ class EmailFailure extends GenericMixedMetric | ||||
|      */ | ||||
|     public $string_metric7 = ''; | ||||
| 
 | ||||
|     public function __construct($string_metric7) { | ||||
|     public function __construct($string_metric7) | ||||
|     { | ||||
|         $this->string_metric7 = $string_metric7; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -15,7 +15,6 @@ use Turbo124\Beacon\ExampleMetric\GenericMixedMetric; | ||||
| 
 | ||||
| class EmailSuccess extends GenericMixedMetric | ||||
| { | ||||
| 
 | ||||
|     /** | ||||
|      * The type of Sample. | ||||
|      * | ||||
| @ -72,8 +71,8 @@ class EmailSuccess extends GenericMixedMetric | ||||
|      */ | ||||
|     public $string_metric7 = ''; | ||||
| 
 | ||||
|     public function __construct($string_metric7) { | ||||
|     public function __construct($string_metric7) | ||||
|     { | ||||
|         $this->string_metric7 = $string_metric7; | ||||
|     } | ||||
|      | ||||
| } | ||||
|  | ||||
| @ -71,7 +71,8 @@ class EmailBounce extends GenericMixedMetric | ||||
|      */ | ||||
|     public $int_metric1 = 1; | ||||
| 
 | ||||
|     public function __construct($string_metric5,$string_metric6,$string_metric7) { | ||||
|     public function __construct($string_metric5, $string_metric6, $string_metric7) | ||||
|     { | ||||
|         $this->string_metric5 = $string_metric5; | ||||
|         $this->string_metric6 = $string_metric6; | ||||
|         $this->string_metric7 = $string_metric7; | ||||
|  | ||||
| @ -71,7 +71,8 @@ class EmailSpam extends GenericMixedMetric | ||||
|      */ | ||||
|     public $int_metric1 = 1; | ||||
| 
 | ||||
|     public function __construct($string_metric5,$string_metric6,$string_metric7) { | ||||
|     public function __construct($string_metric5, $string_metric6, $string_metric7) | ||||
|     { | ||||
|         $this->string_metric5 = $string_metric5; | ||||
|         $this->string_metric6 = $string_metric6; | ||||
|         $this->string_metric7 = $string_metric7; | ||||
|  | ||||
| @ -15,7 +15,6 @@ use Turbo124\Beacon\ExampleMetric\GenericMixedMetric; | ||||
| 
 | ||||
| class QueueSize extends GenericMixedMetric | ||||
| { | ||||
| 
 | ||||
|     /** | ||||
|      * The type of Sample. | ||||
|      * | ||||
| @ -72,8 +71,8 @@ class QueueSize extends GenericMixedMetric | ||||
|      */ | ||||
|     public $string_metric7 = ''; | ||||
| 
 | ||||
|     public function __construct($int_metric1) { | ||||
|     public function __construct($int_metric1) | ||||
|     { | ||||
|         $this->int_metric1 = $int_metric1; | ||||
|     } | ||||
|      | ||||
| } | ||||
|  | ||||
| @ -12,7 +12,6 @@ | ||||
| 
 | ||||
| namespace App\DataMapper\Billing; | ||||
| 
 | ||||
| 
 | ||||
| class SubscriptionContextMapper | ||||
| { | ||||
|     /** | ||||
|  | ||||
| @ -12,7 +12,6 @@ | ||||
| 
 | ||||
| namespace App\DataMapper\Billing; | ||||
| 
 | ||||
| 
 | ||||
| class WebhookConfiguration | ||||
| { | ||||
|     /** | ||||
| @ -33,11 +32,11 @@ class WebhookConfiguration | ||||
|     /** | ||||
|      * @var string | ||||
|      */ | ||||
|     public $post_purchase_body =  ''; | ||||
|     public $post_purchase_body = ''; | ||||
| 
 | ||||
|     /** | ||||
|      * @var string | ||||
|      */  | ||||
|      */ | ||||
|     public $post_purchase_rest_method = 'POST'; | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -13,89 +13,88 @@ namespace App\DataMapper; | ||||
| 
 | ||||
| class ClientRegistrationFields | ||||
| { | ||||
| 
 | ||||
|     public static function generate() | ||||
|     { | ||||
|         $data =  | ||||
|         $data = | ||||
|         [ | ||||
|             [ | ||||
|                 'key' => 'first_name', | ||||
|                 'required' => true | ||||
|                 'required' => true, | ||||
|             ], | ||||
|             [ | ||||
|                 'key' => 'last_name', | ||||
|                 'required' => true | ||||
|                 'required' => true, | ||||
|             ], | ||||
|             [ | ||||
|                 'key' => 'email', | ||||
|                 'required' => true | ||||
|                 'required' => true, | ||||
|             ], | ||||
|             [ | ||||
|                 'key' => 'phone', | ||||
|                 'required' => false | ||||
|                 'required' => false, | ||||
|             ], | ||||
|             [ | ||||
|                 'key' => 'password', | ||||
|                 'required' => true | ||||
|             ],  | ||||
|                 'required' => true, | ||||
|             ], | ||||
|             [ | ||||
|                 'key' => 'name', | ||||
|                 'required' => false | ||||
|                 'required' => false, | ||||
|             ], | ||||
|             [ | ||||
|                 'key' => 'website', | ||||
|                 'required' => false | ||||
|                 'required' => false, | ||||
|             ], | ||||
|             [ | ||||
|                 'key' => 'address1', | ||||
|                 'required' => false | ||||
|                 'required' => false, | ||||
|             ], | ||||
|             [ | ||||
|                 'key' => 'address2', | ||||
|                 'required' => false | ||||
|                 'required' => false, | ||||
|             ], | ||||
|             [ | ||||
|                 'key' => 'city', | ||||
|                 'required' => false | ||||
|                 'required' => false, | ||||
|             ], | ||||
|             [ | ||||
|                 'key' => 'state', | ||||
|                 'required' => false | ||||
|                 'required' => false, | ||||
|             ], | ||||
|             [ | ||||
|                 'key' => 'postal_code', | ||||
|                 'required' => false | ||||
|             ],             | ||||
|                 'required' => false, | ||||
|             ], | ||||
|             [ | ||||
|                 'key' => 'country_id', | ||||
|                 'required' => false | ||||
|             ],             | ||||
|                 'required' => false, | ||||
|             ], | ||||
|             [ | ||||
|                 'key' => 'custom_value1', | ||||
|                 'required' => false | ||||
|             ],             | ||||
|                 'required' => false, | ||||
|             ], | ||||
|             [ | ||||
|                 'key' => 'custom_value2', | ||||
|                 'required' => false | ||||
|                 'required' => false, | ||||
|             ], | ||||
|             [ | ||||
|                 'key' => 'custom_value3', | ||||
|                 'required' => false | ||||
|             ],             | ||||
|                 'required' => false, | ||||
|             ], | ||||
|             [ | ||||
|                 'key' => 'custom_value4', | ||||
|                 'required' => false | ||||
|             ],                        | ||||
|                 'required' => false, | ||||
|             ], | ||||
|             [ | ||||
|                 'key' => 'public_notes', | ||||
|                 'required' => false | ||||
|             ],    | ||||
|                 'required' => false, | ||||
|             ], | ||||
|             [ | ||||
|                 'key' => 'vat_number', | ||||
|                 'required' => false | ||||
|             ],           | ||||
|                 'required' => false, | ||||
|             ], | ||||
|         ]; | ||||
| 
 | ||||
|         return $data; | ||||
|     } | ||||
| } | ||||
| } | ||||
|  | ||||
| @ -30,6 +30,7 @@ class ClientSettings extends BaseSettings | ||||
|      * Settings which which are unique to client settings. | ||||
|      */ | ||||
|     public $industry_id; | ||||
| 
 | ||||
|     public $size_id; | ||||
| 
 | ||||
|     public static $casts = [ | ||||
|  | ||||
| @ -31,20 +31,29 @@ class CompanySettings extends BaseSettings | ||||
|     public $lock_invoices = 'off'; //off,when_sent,when_paid //@implemented
 | ||||
| 
 | ||||
|     public $enable_client_portal_tasks = false; //@ben to implement
 | ||||
| 
 | ||||
|     public $show_all_tasks_client_portal = 'invoiced'; // all, uninvoiced, invoiced
 | ||||
| 
 | ||||
|     public $enable_client_portal_password = false; //@implemented
 | ||||
| 
 | ||||
|     public $enable_client_portal = true; //@implemented
 | ||||
| 
 | ||||
|     public $enable_client_portal_dashboard = false; // @TODO There currently is no dashboard so this is pending
 | ||||
| 
 | ||||
|     public $signature_on_pdf = false; //@implemented
 | ||||
| 
 | ||||
|     public $document_email_attachment = false; //@TODO I assume this is 3rd party attachments on the entity to be included
 | ||||
| 
 | ||||
|     public $portal_design_id = '1'; //?@deprecated
 | ||||
| 
 | ||||
|     public $timezone_id = ''; //@implemented
 | ||||
| 
 | ||||
|     public $date_format_id = ''; //@implemented
 | ||||
| 
 | ||||
|     public $military_time = false; // @TODOImplemented in Tasks only?
 | ||||
| 
 | ||||
|     public $language_id = ''; //@implemented
 | ||||
| 
 | ||||
|     public $show_currency_code = false; //@implemented
 | ||||
| 
 | ||||
|     public $company_gateway_ids = ''; //@implemented
 | ||||
| @ -52,243 +61,379 @@ class CompanySettings extends BaseSettings | ||||
|     public $currency_id = '1'; //@implemented
 | ||||
| 
 | ||||
|     public $custom_value1 = ''; //@implemented
 | ||||
| 
 | ||||
|     public $custom_value2 = ''; //@implemented
 | ||||
| 
 | ||||
|     public $custom_value3 = ''; //@implemented
 | ||||
| 
 | ||||
|     public $custom_value4 = ''; //@implemented
 | ||||
| 
 | ||||
|     public $default_task_rate = 0; // @TODO Where do we inject this?
 | ||||
| 
 | ||||
|     public $payment_terms = ''; //@implemented
 | ||||
| 
 | ||||
|     public $send_reminders = true; //@TODO
 | ||||
| 
 | ||||
|     public $custom_message_dashboard = ''; // @TODO There currently is no dashboard so this is pending
 | ||||
| 
 | ||||
|     public $custom_message_unpaid_invoice = ''; | ||||
| 
 | ||||
|     public $custom_message_paid_invoice = ''; | ||||
| 
 | ||||
|     public $custom_message_unapproved_quote = ''; | ||||
| 
 | ||||
|     public $auto_archive_quote = false; //@implemented
 | ||||
| 
 | ||||
|     public $auto_convert_quote = true; //@implemented
 | ||||
| 
 | ||||
|     public $auto_email_invoice = true; //@only used for Recurring Invoices, if set to false, we never send?
 | ||||
| 
 | ||||
|     public $entity_send_time = 6; | ||||
| 
 | ||||
|     public $inclusive_taxes = false; //@implemented
 | ||||
| 
 | ||||
|     public $quote_footer = ''; //@implmented
 | ||||
| 
 | ||||
|     public $translations; | ||||
| 
 | ||||
|     public $counter_number_applied = 'when_saved'; // when_saved , when_sent //@implemented
 | ||||
| 
 | ||||
|     public $quote_number_applied = 'when_saved'; // when_saved , when_sent //@implemented
 | ||||
| 
 | ||||
|     /* Counters */ | ||||
|     public $invoice_number_pattern = ''; //@implemented
 | ||||
| 
 | ||||
|     public $invoice_number_counter = 1; //@implemented
 | ||||
| 
 | ||||
|     public $recurring_invoice_number_pattern = ''; //@implemented
 | ||||
| 
 | ||||
|     public $recurring_invoice_number_counter = 1; //@implemented
 | ||||
| 
 | ||||
|     public $quote_number_pattern = ''; //@implemented
 | ||||
| 
 | ||||
|     public $quote_number_counter = 1; //@implemented
 | ||||
| 
 | ||||
|     public $client_number_pattern = ''; //@implemented
 | ||||
| 
 | ||||
|     public $client_number_counter = 1; //@implemented
 | ||||
| 
 | ||||
|     public $credit_number_pattern = ''; //@implemented
 | ||||
| 
 | ||||
|     public $credit_number_counter = 1; //@implemented
 | ||||
| 
 | ||||
|     public $task_number_pattern = ''; //@implemented
 | ||||
| 
 | ||||
|     public $task_number_counter = 1; //@implemented
 | ||||
| 
 | ||||
|     public $expense_number_pattern = ''; //@implemented
 | ||||
| 
 | ||||
|     public $expense_number_counter = 1; //@implemented
 | ||||
| 
 | ||||
|     public $recurring_expense_number_pattern = ''; | ||||
| 
 | ||||
|     public $recurring_expense_number_counter = 1; | ||||
| 
 | ||||
|     public $recurring_quote_number_pattern = ''; | ||||
| 
 | ||||
|     public $recurring_quote_number_counter = 1; | ||||
| 
 | ||||
|     public $vendor_number_pattern = ''; //@implemented
 | ||||
| 
 | ||||
|     public $vendor_number_counter = 1; //@implemented
 | ||||
| 
 | ||||
|     public $ticket_number_pattern = ''; //@implemented
 | ||||
| 
 | ||||
|     public $ticket_number_counter = 1; //@implemented
 | ||||
| 
 | ||||
|     public $payment_number_pattern = ''; //@implemented
 | ||||
| 
 | ||||
|     public $payment_number_counter = 1; //@implemented
 | ||||
| 
 | ||||
|     public $project_number_pattern = ''; //@implemented
 | ||||
| 
 | ||||
|     public $project_number_counter = 1; //@implemented
 | ||||
| 
 | ||||
|     public $purchase_order_number_pattern = ''; //@implemented
 | ||||
| 
 | ||||
|     public $purchase_order_number_counter = 1; //@implemented
 | ||||
| 
 | ||||
|     public $shared_invoice_quote_counter = false; //@implemented
 | ||||
| 
 | ||||
|     public $shared_invoice_credit_counter = false; //@implemented
 | ||||
| 
 | ||||
|     public $recurring_number_prefix = ''; //@implemented
 | ||||
| 
 | ||||
|     public $reset_counter_frequency_id = '0'; //@implemented
 | ||||
| 
 | ||||
|     public $reset_counter_date = ''; //@implemented
 | ||||
| 
 | ||||
|     public $counter_padding = 4; //@implemented
 | ||||
| 
 | ||||
|     public $auto_bill = 'off'; //off,always,optin,optout //@implemented
 | ||||
| 
 | ||||
|     public $auto_bill_date = 'on_due_date'; // on_due_date , on_send_date //@implemented
 | ||||
| 
 | ||||
|     public $invoice_terms = ''; //@implemented
 | ||||
| 
 | ||||
|     public $quote_terms = ''; //@implemented
 | ||||
| 
 | ||||
|     public $invoice_taxes = 0; // ? used in AP only?
 | ||||
| 
 | ||||
|     public $invoice_design_id = 'Wpmbk5ezJn'; //@implemented
 | ||||
| 
 | ||||
|     public $quote_design_id = 'Wpmbk5ezJn'; //@implemented
 | ||||
| 
 | ||||
|     public $credit_design_id = 'Wpmbk5ezJn'; //@implemented
 | ||||
| 
 | ||||
|     public $purchase_order_design_id = 'Wpmbk5ezJn'; | ||||
| 
 | ||||
|     public $purchase_order_footer = ''; //@implemented
 | ||||
| 
 | ||||
|     public $purchase_order_terms = ''; //@implemented
 | ||||
| 
 | ||||
|     public $purchase_order_public_notes = ''; //@implemented
 | ||||
| 
 | ||||
|     public $require_purchase_order_signature = false;  //@TODO ben to confirm
 | ||||
|      | ||||
| 
 | ||||
|     public $invoice_footer = ''; //@implemented
 | ||||
| 
 | ||||
|     public $credit_footer = ''; //@implemented
 | ||||
| 
 | ||||
|     public $credit_terms = ''; //@implemented
 | ||||
| 
 | ||||
|     public $invoice_labels = ''; //@TODO used in AP only?
 | ||||
| 
 | ||||
|     public $tax_name1 = ''; //@TODO where do we use this?
 | ||||
| 
 | ||||
|     public $tax_rate1 = 0; //@TODO where do we use this?
 | ||||
| 
 | ||||
|     public $tax_name2 = ''; //@TODO where do we use this?
 | ||||
| 
 | ||||
|     public $tax_rate2 = 0; //@TODO where do we use this?
 | ||||
| 
 | ||||
|     public $tax_name3 = ''; //@TODO where do we use this?
 | ||||
| 
 | ||||
|     public $tax_rate3 = 0; //@TODO where do we use this?
 | ||||
| 
 | ||||
|     public $payment_type_id = '0'; //@TODO where do we use this?
 | ||||
| 
 | ||||
|     public $valid_until = ''; //@implemented
 | ||||
| 
 | ||||
|     public $show_accept_invoice_terms = false; //@TODO ben to confirm
 | ||||
| 
 | ||||
|     public $show_accept_quote_terms = false;  //@TODO ben to confirm
 | ||||
| 
 | ||||
|     public $require_invoice_signature = false;  //@TODO ben to confirm
 | ||||
| 
 | ||||
|     public $require_quote_signature = false;  //@TODO ben to confirm
 | ||||
| 
 | ||||
|     //email settings
 | ||||
|     public $email_sending_method = 'default'; //enum 'default','gmail','office365' //@implemented
 | ||||
| 
 | ||||
|     public $gmail_sending_user_id = '0'; //@implemented
 | ||||
| 
 | ||||
|     public $reply_to_email = ''; //@implemented
 | ||||
| 
 | ||||
|     public $reply_to_name = ''; //@implemented
 | ||||
| 
 | ||||
|     public $bcc_email = ''; //@TODO
 | ||||
| 
 | ||||
|     public $pdf_email_attachment = false; //@implemented
 | ||||
| 
 | ||||
|     public $ubl_email_attachment = false; //@implemented
 | ||||
| 
 | ||||
|     public $email_style = 'light'; //plain, light, dark, custom  //@implemented
 | ||||
| 
 | ||||
|     public $email_style_custom = '';      //the template itself  //@implemented
 | ||||
| 
 | ||||
|     public $email_subject_invoice = '';  //@implemented
 | ||||
| 
 | ||||
|     public $email_subject_quote = '';  //@implemented
 | ||||
| 
 | ||||
|     public $email_subject_credit = ''; //@implemented
 | ||||
| 
 | ||||
|     public $email_subject_payment = ''; //@implemented
 | ||||
| 
 | ||||
|     public $email_subject_payment_partial = ''; //@implemented
 | ||||
| 
 | ||||
|     public $email_subject_statement = ''; //@implemented
 | ||||
| 
 | ||||
|     public $email_subject_purchase_order = ''; //@implemented
 | ||||
| 
 | ||||
|     public $email_template_purchase_order = ''; //@implemented
 | ||||
| 
 | ||||
|     public $email_template_invoice = ''; //@implemented
 | ||||
| 
 | ||||
|     public $email_template_credit = ''; //@implemented
 | ||||
| 
 | ||||
|     public $email_template_quote = ''; //@implemented
 | ||||
| 
 | ||||
|     public $email_template_payment = ''; //@implemented
 | ||||
| 
 | ||||
|     public $email_template_payment_partial = ''; //@implemented
 | ||||
| 
 | ||||
|     public $email_template_statement = ''; //@implemented
 | ||||
| 
 | ||||
|     public $email_subject_reminder1 = ''; //@implemented
 | ||||
| 
 | ||||
|     public $email_subject_reminder2 = ''; //@implemented
 | ||||
| 
 | ||||
|     public $email_subject_reminder3 = ''; //@implemented
 | ||||
| 
 | ||||
|     public $email_subject_reminder_endless = ''; //@implemented
 | ||||
| 
 | ||||
|     public $email_template_reminder1 = ''; //@implemented
 | ||||
| 
 | ||||
|     public $email_template_reminder2 = ''; //@implemented
 | ||||
| 
 | ||||
|     public $email_template_reminder3 = ''; //@implemented
 | ||||
| 
 | ||||
|     public $email_template_reminder_endless = ''; //@implemented
 | ||||
| 
 | ||||
|     public $email_signature = ''; //@implemented
 | ||||
| 
 | ||||
|     public $enable_email_markup = true; //@TODO -
 | ||||
| 
 | ||||
|     public $email_subject_custom1 = ''; //@TODO
 | ||||
| 
 | ||||
|     public $email_subject_custom2 = ''; //@TODO
 | ||||
| 
 | ||||
|     public $email_subject_custom3 = ''; //@TODO
 | ||||
| 
 | ||||
|     public $email_template_custom1 = ''; //@TODO
 | ||||
| 
 | ||||
|     public $email_template_custom2 = ''; //@TODO
 | ||||
| 
 | ||||
|     public $email_template_custom3 = ''; //@TODO
 | ||||
| 
 | ||||
|     public $enable_reminder1 = false; //@implmemented
 | ||||
| 
 | ||||
|     public $enable_reminder2 = false; //@implmemented
 | ||||
| 
 | ||||
|     public $enable_reminder3 = false; //@implmemented
 | ||||
| 
 | ||||
|     public $enable_reminder_endless = false; //@implmemented
 | ||||
| 
 | ||||
|     public $num_days_reminder1 = 0;//@implmemented
 | ||||
|     public $num_days_reminder2 = 0;//@implmemented
 | ||||
|     public $num_days_reminder3 = 0;//@implmemented
 | ||||
|     public $num_days_reminder1 = 0; //@implmemented
 | ||||
| 
 | ||||
|     public $num_days_reminder2 = 0; //@implmemented
 | ||||
| 
 | ||||
|     public $num_days_reminder3 = 0; //@implmemented
 | ||||
| 
 | ||||
|     public $schedule_reminder1 = ''; // (enum: after_invoice_date, before_due_date, after_due_date) implmemented
 | ||||
| 
 | ||||
|     public $schedule_reminder2 = ''; // (enum: after_invoice_date, before_due_date, after_due_date) implmemented
 | ||||
| 
 | ||||
|     public $schedule_reminder3 = ''; // (enum: after_invoice_date, before_due_date, after_due_date) implmemented
 | ||||
| 
 | ||||
|     public $reminder_send_time = 0; //number of seconds from UTC +0 to send reminders @TODO
 | ||||
| 
 | ||||
|     public $late_fee_amount1 = 0; //@implemented
 | ||||
| 
 | ||||
|     public $late_fee_amount2 = 0; //@implemented
 | ||||
| 
 | ||||
|     public $late_fee_amount3 = 0; //@implemented
 | ||||
| 
 | ||||
|     public $late_fee_percent1 = 0; //@implemented
 | ||||
| 
 | ||||
|     public $late_fee_percent2 = 0; //@implemented
 | ||||
| 
 | ||||
|     public $late_fee_percent3 = 0; //@implemented
 | ||||
| 
 | ||||
|     public $endless_reminder_frequency_id = '0'; //@implemented
 | ||||
| 
 | ||||
|     public $late_fee_endless_amount = 0; //@implemented
 | ||||
| 
 | ||||
|     public $late_fee_endless_percent = 0; //@implemented
 | ||||
| 
 | ||||
|     public $client_online_payment_notification = true; //@todo implement in notifications check this bool prior to sending payment notification to client
 | ||||
| 
 | ||||
|     public $client_manual_payment_notification = true; //@todo implement in notifications check this bool prior to sending manual payment notification to client
 | ||||
| 
 | ||||
|     /* Company Meta data that we can use to build sub companies*/ | ||||
| 
 | ||||
|     public $name = ''; //@implemented
 | ||||
| 
 | ||||
|     public $company_logo = ''; //@implemented
 | ||||
| 
 | ||||
|     public $website = ''; //@implemented
 | ||||
| 
 | ||||
|     public $address1 = ''; //@implemented
 | ||||
| 
 | ||||
|     public $address2 = ''; //@implemented
 | ||||
| 
 | ||||
|     public $city = ''; //@implemented
 | ||||
| 
 | ||||
|     public $state = ''; //@implemented
 | ||||
| 
 | ||||
|     public $postal_code = ''; //@implemented
 | ||||
| 
 | ||||
|     public $phone = ''; //@implemented
 | ||||
| 
 | ||||
|     public $email = ''; //@implemented
 | ||||
| 
 | ||||
|     public $country_id; //@implemented
 | ||||
| 
 | ||||
|     public $vat_number = ''; //@implemented
 | ||||
| 
 | ||||
|     public $id_number = ''; //@implemented
 | ||||
| 
 | ||||
|     public $page_size = 'A4';  //Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6
 | ||||
| 
 | ||||
|     public $page_layout = 'portrait'; | ||||
| 
 | ||||
|     public $font_size = 7; //@implemented
 | ||||
| 
 | ||||
|     public $primary_font = 'Roboto'; | ||||
| 
 | ||||
|     public $secondary_font = 'Roboto'; | ||||
| 
 | ||||
|     public $primary_color = '#298AAB'; | ||||
| 
 | ||||
|     public $secondary_color = '#7081e0'; | ||||
| 
 | ||||
|     public $page_numbering = false; | ||||
| 
 | ||||
|     public $page_numbering_alignment = 'C';  //C,R,L
 | ||||
| 
 | ||||
|     public $hide_paid_to_date = false; //@TODO where?
 | ||||
| 
 | ||||
|     public $embed_documents = false; //@TODO where?
 | ||||
| 
 | ||||
|     public $all_pages_header = false; //@deprecated 31-05-2021
 | ||||
| 
 | ||||
|     public $all_pages_footer = false; //@deprecated 31-05-2021
 | ||||
| 
 | ||||
|     public $pdf_variables = ''; //@implemented
 | ||||
| 
 | ||||
|     public $portal_custom_head = ''; //@TODO @BEN
 | ||||
| 
 | ||||
|     public $portal_custom_css = ''; //@TODO @BEN
 | ||||
| 
 | ||||
|     public $portal_custom_footer = ''; //@TODO @BEN
 | ||||
| 
 | ||||
|     public $portal_custom_js = ''; //@TODO @BEN
 | ||||
| 
 | ||||
|     public $client_can_register = false; //@deorecated 04/06/2021
 | ||||
| 
 | ||||
|     public $client_portal_terms = ''; //@TODO @BEN
 | ||||
| 
 | ||||
|     public $client_portal_privacy_policy = ''; //@TODO @BEN
 | ||||
| 
 | ||||
|     public $client_portal_enable_uploads = false; //@implemented
 | ||||
| 
 | ||||
|     public $client_portal_allow_under_payment = false; //@implemented
 | ||||
| 
 | ||||
|     public $client_portal_under_payment_minimum = 0; //@implemented
 | ||||
| 
 | ||||
|     public $client_portal_allow_over_payment = false; //@implemented
 | ||||
| 
 | ||||
|     public $use_credits_payment = 'off'; //always, option, off //@implemented
 | ||||
| 
 | ||||
|     public $hide_empty_columns_on_pdf = false; | ||||
| 
 | ||||
|     public $email_from_name = ''; | ||||
| 
 | ||||
|     public $auto_archive_invoice_cancelled = false; | ||||
| 
 | ||||
|     public $vendor_portal_enable_uploads=false; | ||||
|  | ||||
| @ -26,12 +26,11 @@ class DefaultSettings extends BaseSettings | ||||
| 
 | ||||
|     /** | ||||
|      * @return stdClass | ||||
|      * | ||||
|      */ | ||||
|     public static function userSettings() : stdClass | ||||
|     { | ||||
|         return (object) [ | ||||
|         //    class_basename(User::class) => self::userSettingsObject(),
 | ||||
|             //    class_basename(User::class) => self::userSettingsObject(),
 | ||||
|         ]; | ||||
|     } | ||||
| 
 | ||||
| @ -41,7 +40,7 @@ class DefaultSettings extends BaseSettings | ||||
|     private static function userSettingsObject() : stdClass | ||||
|     { | ||||
|         return (object) [ | ||||
|         //    'per_page' => self::$per_page,
 | ||||
|             //    'per_page' => self::$per_page,
 | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -162,11 +162,9 @@ class EmailTemplateDefaults | ||||
| 
 | ||||
|     public static function emailPurchaseOrderTemplate() | ||||
|     { | ||||
| 
 | ||||
|         $purchase_order_message = '<p>$vendor<br><br>'.self::transformText('purchase_order_message').'</p><div class="center">$view_button</div>'; | ||||
| 
 | ||||
|         return $purchase_order_message; | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     public static function emailPaymentTemplate() | ||||
| @ -249,6 +247,6 @@ class EmailTemplateDefaults | ||||
|     { | ||||
|         //preformat the string, removing trailing colons.
 | ||||
| 
 | ||||
|         return str_replace(':', '$', rtrim( ctrans('texts.'.$string), ":")); | ||||
|         return str_replace(':', '$', rtrim(ctrans('texts.'.$string), ':')); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -20,67 +20,123 @@ use stdClass; | ||||
| class FreeCompanySettings extends BaseSettings | ||||
| { | ||||
|     use MakesHash; | ||||
| 
 | ||||
|     /*Group settings based on functionality*/ | ||||
|     public $credit_design_id = 'VolejRejNm'; | ||||
| 
 | ||||
|     public $client_number_pattern = ''; | ||||
| 
 | ||||
|     public $client_number_counter = 1; | ||||
| 
 | ||||
|     public $credit_number_pattern = ''; | ||||
| 
 | ||||
|     public $credit_number_counter = 1; | ||||
| 
 | ||||
|     public $currency_id = '1'; | ||||
| 
 | ||||
|     public $custom_value1 = ''; | ||||
| 
 | ||||
|     public $custom_value2 = ''; | ||||
| 
 | ||||
|     public $custom_value3 = ''; | ||||
| 
 | ||||
|     public $custom_value4 = ''; | ||||
| 
 | ||||
|     public $date_format_id = ''; | ||||
| 
 | ||||
| //    public $enabled_item_tax_rates          = 0;
 | ||||
|     public $expense_number_pattern = ''; | ||||
| 
 | ||||
|     public $expense_number_counter = 1; | ||||
| 
 | ||||
|     public $inclusive_taxes = false; | ||||
| 
 | ||||
|     public $invoice_design_id = 'VolejRejNm'; | ||||
| 
 | ||||
|     public $invoice_number_pattern = ''; | ||||
| 
 | ||||
|     public $invoice_number_counter = 1; | ||||
| 
 | ||||
|     public $invoice_taxes = 0; | ||||
| 
 | ||||
|     public $language_id = ''; | ||||
| 
 | ||||
|     public $military_time = false; | ||||
| 
 | ||||
|     public $payment_number_pattern = ''; | ||||
| 
 | ||||
|     public $payment_number_counter = 1; | ||||
| 
 | ||||
|     public $payment_terms = ''; | ||||
| 
 | ||||
|     public $payment_type_id = '0'; | ||||
| 
 | ||||
|     public $portal_design_id = '1'; | ||||
| 
 | ||||
|     public $quote_design_id = 'VolejRejNm'; | ||||
| 
 | ||||
|     public $quote_number_pattern = ''; | ||||
| 
 | ||||
|     public $quote_number_counter = 1; | ||||
| 
 | ||||
|     public $timezone_id = ''; | ||||
| 
 | ||||
|     public $show_currency_code = false; | ||||
| 
 | ||||
|     public $company_gateway_ids = ''; | ||||
| 
 | ||||
|     public $task_number_pattern = ''; | ||||
| 
 | ||||
|     public $task_number_counter = 1; | ||||
| 
 | ||||
|     public $tax_name1 = ''; | ||||
| 
 | ||||
|     public $tax_rate1 = 0; | ||||
| 
 | ||||
|     public $tax_name2 = ''; | ||||
| 
 | ||||
|     public $tax_rate2 = 0; | ||||
| 
 | ||||
|     public $tax_name3 = ''; | ||||
| 
 | ||||
|     public $tax_rate3 = 0; | ||||
| 
 | ||||
|     public $ticket_number_pattern = ''; | ||||
| 
 | ||||
|     public $ticket_number_counter = 1; | ||||
| 
 | ||||
|     public $translations; | ||||
| 
 | ||||
|     public $vendor_number_pattern = ''; | ||||
| 
 | ||||
|     public $vendor_number_counter = 1; | ||||
| 
 | ||||
|     /* Company Meta data that we can use to build sub companies*/ | ||||
| 
 | ||||
|     public $address1 = ''; | ||||
| 
 | ||||
|     public $address2 = ''; | ||||
| 
 | ||||
|     public $city = ''; | ||||
| 
 | ||||
|     public $company_logo = ''; | ||||
| 
 | ||||
|     public $country_id; | ||||
| 
 | ||||
|     public $email = ''; | ||||
| 
 | ||||
|     public $id_number = ''; | ||||
| 
 | ||||
|     public $name = ''; | ||||
| 
 | ||||
|     public $phone = ''; | ||||
| 
 | ||||
|     public $postal_code = ''; | ||||
| 
 | ||||
|     public $state = ''; | ||||
| 
 | ||||
|     public $vat_number = ''; | ||||
| 
 | ||||
|     public $website = ''; | ||||
| 
 | ||||
|     public static $casts = [ | ||||
|  | ||||
| @ -22,8 +22,7 @@ use App\Models\TransactionEvent; | ||||
|  */ | ||||
| class BaseTransaction implements TransactionInterface | ||||
| { | ||||
|      | ||||
|     public $event_id = TransactionEvent::INVOICE_MARK_PAID;  | ||||
|     public $event_id = TransactionEvent::INVOICE_MARK_PAID; | ||||
| 
 | ||||
|     public array $model = [ | ||||
|         'client_id', | ||||
| @ -56,7 +55,7 @@ class BaseTransaction implements TransactionInterface | ||||
|     { | ||||
|         // $invoice = $data['invoice'];
 | ||||
|         // $payment = $data['payment'];
 | ||||
|         // $client = $data['client']; 
 | ||||
|         // $client = $data['client'];
 | ||||
|         // $credit = $data['credit'];
 | ||||
|         // $payment_request = $data['payment']['payment_request'];
 | ||||
|         // $metadata = $data['metadata'];
 | ||||
| @ -95,6 +94,5 @@ class BaseTransaction implements TransactionInterface | ||||
|         //     'credit_status' => $credit?->status_id,
 | ||||
|         //     'timestamp' => time(),
 | ||||
|         // ];
 | ||||
| 
 | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -22,7 +22,5 @@ use App\Models\TransactionEvent; | ||||
|  */ | ||||
| class ClientStatusTransaction extends BaseTransaction implements TransactionInterface | ||||
| { | ||||
|      | ||||
|     public $event_id = TransactionEvent::CLIENT_STATUS;  | ||||
| 
 | ||||
|     public $event_id = TransactionEvent::CLIENT_STATUS; | ||||
| } | ||||
|  | ||||
| @ -22,7 +22,5 @@ use App\Models\TransactionEvent; | ||||
|  */ | ||||
| class GatewayPaymentMadeTransaction extends BaseTransaction implements TransactionInterface | ||||
| { | ||||
|      | ||||
|     public $event_id = TransactionEvent::GATEWAY_PAYMENT_MADE;  | ||||
| 
 | ||||
|     public $event_id = TransactionEvent::GATEWAY_PAYMENT_MADE; | ||||
| } | ||||
|  | ||||
| @ -22,7 +22,5 @@ use App\Models\TransactionEvent; | ||||
|  */ | ||||
| class InvoiceCancelledTransaction extends BaseTransaction implements TransactionInterface | ||||
| { | ||||
|      | ||||
|     public $event_id = TransactionEvent::INVOICE_CANCELLED;  | ||||
| 
 | ||||
|     public $event_id = TransactionEvent::INVOICE_CANCELLED; | ||||
| } | ||||
|  | ||||
| @ -22,7 +22,5 @@ use App\Models\TransactionEvent; | ||||
|  */ | ||||
| class InvoiceDeletedTransaction extends BaseTransaction implements TransactionInterface | ||||
| { | ||||
|      | ||||
|     public $event_id = TransactionEvent::INVOICE_DELETED;  | ||||
| 
 | ||||
|     public $event_id = TransactionEvent::INVOICE_DELETED; | ||||
| } | ||||
|  | ||||
| @ -22,7 +22,5 @@ use App\Models\TransactionEvent; | ||||
|  */ | ||||
| class InvoiceFeeAppliedTransaction extends BaseTransaction implements TransactionInterface | ||||
| { | ||||
|      | ||||
|     public $event_id = TransactionEvent::INVOICE_FEE_APPLIED;  | ||||
| 
 | ||||
|     public $event_id = TransactionEvent::INVOICE_FEE_APPLIED; | ||||
| } | ||||
|  | ||||
| @ -22,7 +22,5 @@ use App\Models\TransactionEvent; | ||||
|  */ | ||||
| class InvoicePaymentTransaction extends BaseTransaction implements TransactionInterface | ||||
| { | ||||
|      | ||||
|     public $event_id = TransactionEvent::INVOICE_PAYMENT_APPLIED;  | ||||
| 
 | ||||
|     public $event_id = TransactionEvent::INVOICE_PAYMENT_APPLIED; | ||||
| } | ||||
|  | ||||
| @ -22,7 +22,5 @@ use App\Models\TransactionEvent; | ||||
|  */ | ||||
| class InvoiceReversalTransaction extends BaseTransaction implements TransactionInterface | ||||
| { | ||||
|      | ||||
|     public $event_id = TransactionEvent::INVOICE_REVERSED;  | ||||
| 
 | ||||
|     public $event_id = TransactionEvent::INVOICE_REVERSED; | ||||
| } | ||||
|  | ||||
| @ -22,7 +22,5 @@ use App\Models\TransactionEvent; | ||||
|  */ | ||||
| class InvoiceUpdatedTransaction extends BaseTransaction implements TransactionInterface | ||||
| { | ||||
|      | ||||
|     public $event_id = TransactionEvent::INVOICE_UPDATED;  | ||||
| 
 | ||||
|     public $event_id = TransactionEvent::INVOICE_UPDATED; | ||||
| } | ||||
|  | ||||
| @ -22,7 +22,5 @@ use App\Models\TransactionEvent; | ||||
|  */ | ||||
| class MarkPaidTransaction extends BaseTransaction implements TransactionInterface | ||||
| { | ||||
|      | ||||
|     public $event_id = TransactionEvent::INVOICE_MARK_PAID;  | ||||
| 
 | ||||
|     public $event_id = TransactionEvent::INVOICE_MARK_PAID; | ||||
| } | ||||
|  | ||||
| @ -22,7 +22,5 @@ use App\Models\TransactionEvent; | ||||
|  */ | ||||
| class PaymentAppliedTransaction extends BaseTransaction implements TransactionInterface | ||||
| { | ||||
|      | ||||
|     public $event_id = TransactionEvent::PAYMENT_APPLIED;  | ||||
| 
 | ||||
|     public $event_id = TransactionEvent::PAYMENT_APPLIED; | ||||
| } | ||||
|  | ||||
| @ -22,7 +22,5 @@ use App\Models\TransactionEvent; | ||||
|  */ | ||||
| class PaymentDeletedTransaction extends BaseTransaction implements TransactionInterface | ||||
| { | ||||
|      | ||||
|     public $event_id = TransactionEvent::PAYMENT_DELETED;  | ||||
| 
 | ||||
|     public $event_id = TransactionEvent::PAYMENT_DELETED; | ||||
| } | ||||
|  | ||||
| @ -22,7 +22,5 @@ use App\Models\TransactionEvent; | ||||
|  */ | ||||
| class PaymentFailedTransaction extends BaseTransaction implements TransactionInterface | ||||
| { | ||||
|      | ||||
|     public $event_id = TransactionEvent::PAYMENT_FAILED;  | ||||
| 
 | ||||
|     public $event_id = TransactionEvent::PAYMENT_FAILED; | ||||
| } | ||||
|  | ||||
| @ -22,7 +22,5 @@ use App\Models\TransactionEvent; | ||||
|  */ | ||||
| class PaymentMadeTransaction extends BaseTransaction implements TransactionInterface | ||||
| { | ||||
|      | ||||
|     public $event_id = TransactionEvent::PAYMENT_MADE;  | ||||
| 
 | ||||
|     public $event_id = TransactionEvent::PAYMENT_MADE; | ||||
| } | ||||
|  | ||||
| @ -22,7 +22,5 @@ use App\Models\TransactionEvent; | ||||
|  */ | ||||
| class PaymentRefundedTransaction extends BaseTransaction implements TransactionInterface | ||||
| { | ||||
|      | ||||
|     public $event_id = TransactionEvent::PAYMENT_REFUND;  | ||||
| 
 | ||||
|     public $event_id = TransactionEvent::PAYMENT_REFUND; | ||||
| } | ||||
|  | ||||
| @ -28,7 +28,7 @@ class ClientWasRestored | ||||
|     public $client; | ||||
| 
 | ||||
|     public $fromDeleted; | ||||
|      | ||||
| 
 | ||||
|     public $company; | ||||
| 
 | ||||
|     public $event_vars; | ||||
|  | ||||
| @ -28,6 +28,7 @@ class CreditWasEmailed | ||||
|     public $event_vars; | ||||
| 
 | ||||
|     public $template; | ||||
| 
 | ||||
|     /** | ||||
|      * Create a new event instance. | ||||
|      * | ||||
|  | ||||
| @ -21,6 +21,7 @@ use Illuminate\Queue\SerializesModels; | ||||
| class CreditWasMarkedSent | ||||
| { | ||||
|     use SerializesModels; | ||||
| 
 | ||||
|     /** | ||||
|      * @var Credit | ||||
|      */ | ||||
|  | ||||
| @ -32,6 +32,7 @@ class CreditWasRestored | ||||
|     public $event_vars; | ||||
| 
 | ||||
|     public $fromDeleted; | ||||
| 
 | ||||
|     /** | ||||
|      * Create a new event instance. | ||||
|      * | ||||
|  | ||||
| @ -32,6 +32,7 @@ class DesignWasRestored | ||||
|     public $event_vars; | ||||
| 
 | ||||
|     public $fromDeleted; | ||||
| 
 | ||||
|     /** | ||||
|      * Create a new event instance. | ||||
|      * | ||||
|  | ||||
| @ -32,6 +32,7 @@ class DocumentWasRestored | ||||
|     public $event_vars; | ||||
| 
 | ||||
|     public $fromDeleted; | ||||
| 
 | ||||
|     /** | ||||
|      * Create a new event instance. | ||||
|      * | ||||
|  | ||||
| @ -32,6 +32,7 @@ class ExpenseWasRestored | ||||
|     public $event_vars; | ||||
| 
 | ||||
|     public $fromDeleted; | ||||
| 
 | ||||
|     /** | ||||
|      * Create a new event instance. | ||||
|      * | ||||
|  | ||||
| @ -32,7 +32,7 @@ class InvoiceWasRestored | ||||
|     public $company; | ||||
| 
 | ||||
|     public $event_vars; | ||||
|      | ||||
| 
 | ||||
|     /** | ||||
|      * Create a new event instance. | ||||
|      * | ||||
|  | ||||
| @ -26,8 +26,11 @@ class PaymentWasRestored | ||||
|      * @var Payment | ||||
|      */ | ||||
|     public $payment; | ||||
| 
 | ||||
|     public $fromDeleted; | ||||
| 
 | ||||
|     public $company; | ||||
| 
 | ||||
|     public $event_vars; | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -32,6 +32,7 @@ class ProductWasRestored | ||||
|     public $event_vars; | ||||
| 
 | ||||
|     public $fromDeleted; | ||||
| 
 | ||||
|     /** | ||||
|      * Create a new event instance. | ||||
|      * | ||||
|  | ||||
| @ -34,6 +34,7 @@ class PurchaseOrderWasAccepted | ||||
|     public $event_vars; | ||||
| 
 | ||||
|     public $contact; | ||||
| 
 | ||||
|     /** | ||||
|      * Create a new event instance. | ||||
|      * | ||||
|  | ||||
| @ -32,6 +32,7 @@ class PurchaseOrderWasRestored | ||||
|     public $event_vars; | ||||
| 
 | ||||
|     public $fromDeleted; | ||||
| 
 | ||||
|     /** | ||||
|      * Create a new event instance. | ||||
|      * | ||||
|  | ||||
| @ -30,6 +30,7 @@ class QuoteWasEmailed | ||||
|     public $event_vars; | ||||
| 
 | ||||
|     public $template; | ||||
| 
 | ||||
|     /** | ||||
|      * Create a new event instance. | ||||
|      * | ||||
|  | ||||
| @ -29,6 +29,7 @@ class QuoteWasRestored | ||||
|     public $event_vars; | ||||
| 
 | ||||
|     public $fromDeleted; | ||||
| 
 | ||||
|     /** | ||||
|      * Create a new event instance. | ||||
|      * | ||||
|  | ||||
| @ -32,6 +32,7 @@ class RecurringExpenseWasRestored | ||||
|     public $event_vars; | ||||
| 
 | ||||
|     public $fromDeleted; | ||||
| 
 | ||||
|     /** | ||||
|      * Create a new event instance. | ||||
|      * | ||||
|  | ||||
| @ -32,7 +32,7 @@ class RecurringInvoiceWasRestored | ||||
|     public $company; | ||||
| 
 | ||||
|     public $event_vars; | ||||
|      | ||||
| 
 | ||||
|     /** | ||||
|      * Create a new event instance. | ||||
|      * | ||||
|  | ||||
| @ -32,7 +32,7 @@ class RecurringQuoteWasRestored | ||||
|     public $company; | ||||
| 
 | ||||
|     public $event_vars; | ||||
|      | ||||
| 
 | ||||
|     /** | ||||
|      * Create a new event instance. | ||||
|      * | ||||
|  | ||||
| @ -2,8 +2,8 @@ | ||||
| 
 | ||||
| namespace App\Events\Subscription; | ||||
| 
 | ||||
| use App\Models\Subscription; | ||||
| use App\Models\Company; | ||||
| use App\Models\Subscription; | ||||
| use Illuminate\Broadcasting\Channel; | ||||
| use Illuminate\Broadcasting\InteractsWithSockets; | ||||
| use Illuminate\Broadcasting\PresenceChannel; | ||||
|  | ||||
| @ -32,6 +32,7 @@ class SubscriptionWasRestored | ||||
|     public $event_vars; | ||||
| 
 | ||||
|     public $fromDeleted; | ||||
| 
 | ||||
|     /** | ||||
|      * Create a new event instance. | ||||
|      * | ||||
|  | ||||
| @ -32,6 +32,7 @@ class TaskWasRestored | ||||
|     public $event_vars; | ||||
| 
 | ||||
|     public $fromDeleted; | ||||
| 
 | ||||
|     /** | ||||
|      * Create a new event instance. | ||||
|      * | ||||
|  | ||||
							
								
								
									
										1
									
								
								app/Events/Vendor/VendorWasRestored.php
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								app/Events/Vendor/VendorWasRestored.php
									
									
									
									
										vendored
									
									
								
							| @ -32,6 +32,7 @@ class VendorWasRestored | ||||
|     public $event_vars; | ||||
| 
 | ||||
|     public $fromDeleted; | ||||
| 
 | ||||
|     /** | ||||
|      * Create a new event instance. | ||||
|      * | ||||
|  | ||||
| @ -62,6 +62,7 @@ class Handler extends ExceptionHandler | ||||
|      * @var array | ||||
|      */ | ||||
|     protected $dontFlash = [ | ||||
|         'current_password', | ||||
|         'password', | ||||
|         'password_confirmation', | ||||
|     ]; | ||||
| @ -77,37 +78,33 @@ class Handler extends ExceptionHandler | ||||
|     { | ||||
|         if (! Schema::hasTable('accounts')) { | ||||
|             info('account table not found'); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         if(Ninja::isHosted() && !($exception instanceof ValidationException)){ | ||||
| 
 | ||||
|         if (Ninja::isHosted() && ! ($exception instanceof ValidationException)) { | ||||
|             app('sentry')->configureScope(function (Scope $scope): void { | ||||
| 
 | ||||
|                 $name = 'hosted@invoiceninja.com'; | ||||
| 
 | ||||
|                 if(auth()->guard('contact') && auth()->guard('contact')->user()){ | ||||
|                     $name = "Contact = ".auth()->guard('contact')->user()->email; | ||||
|                 if (auth()->guard('contact') && auth()->guard('contact')->user()) { | ||||
|                     $name = 'Contact = '.auth()->guard('contact')->user()->email; | ||||
|                     $key = auth()->guard('contact')->user()->company->account->key; | ||||
|                 } | ||||
|                 elseif (auth()->guard('user') && auth()->guard('user')->user()){ | ||||
|                     $name = "Admin = ".auth()->guard('user')->user()->email;                     | ||||
|                 } elseif (auth()->guard('user') && auth()->guard('user')->user()) { | ||||
|                     $name = 'Admin = '.auth()->guard('user')->user()->email; | ||||
|                     $key = auth()->user()->account->key; | ||||
|                 }  | ||||
|                 else | ||||
|                 } else { | ||||
|                     $key = 'Anonymous'; | ||||
|                  | ||||
|                  $scope->setUser([ | ||||
|                         'id'    => $key, | ||||
|                         'email' => 'hosted@invoiceninja.com', | ||||
|                         'name'  => $name, | ||||
|                     ]); | ||||
|                 } | ||||
| 
 | ||||
|                 $scope->setUser([ | ||||
|                     'id'    => $key, | ||||
|                     'email' => 'hosted@invoiceninja.com', | ||||
|                     'name'  => $name, | ||||
|                 ]); | ||||
|             }); | ||||
| 
 | ||||
|                 app('sentry')->captureException($exception); | ||||
| 
 | ||||
|         } | ||||
|         elseif (app()->bound('sentry') && $this->shouldReport($exception)) { | ||||
|             app('sentry')->captureException($exception); | ||||
|         } elseif (app()->bound('sentry') && $this->shouldReport($exception)) { | ||||
|             app('sentry')->configureScope(function (Scope $scope): void { | ||||
|                 if (auth()->guard('contact') && auth()->guard('contact')->user() && auth()->guard('contact')->user()->company->account->report_errors) { | ||||
|                     $scope->setUser([ | ||||
| @ -130,28 +127,33 @@ class Handler extends ExceptionHandler | ||||
|         } | ||||
| 
 | ||||
|         parent::report($exception); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private function validException($exception) | ||||
|     { | ||||
|         if (strpos($exception->getMessage(), 'file_put_contents') !== false)  | ||||
|         if (strpos($exception->getMessage(), 'file_put_contents') !== false) { | ||||
|             return false; | ||||
|         } | ||||
| 
 | ||||
|         if (strpos($exception->getMessage(), 'Permission denied') !== false)  | ||||
|             return false; | ||||
|          | ||||
|         if (strpos($exception->getMessage(), 'flock') !== false)  | ||||
|         if (strpos($exception->getMessage(), 'Permission denied') !== false) { | ||||
|             return false; | ||||
|         } | ||||
| 
 | ||||
|         if (strpos($exception->getMessage(), 'expects parameter 1 to be resource') !== false)  | ||||
|         if (strpos($exception->getMessage(), 'flock') !== false) { | ||||
|             return false; | ||||
|         } | ||||
| 
 | ||||
|         if (strpos($exception->getMessage(), 'fwrite()') !== false) | ||||
|         if (strpos($exception->getMessage(), 'expects parameter 1 to be resource') !== false) { | ||||
|             return false; | ||||
|          | ||||
|         if(strpos($exception->getMessage(), 'LockableFile') !== false) | ||||
|         } | ||||
| 
 | ||||
|         if (strpos($exception->getMessage(), 'fwrite()') !== false) { | ||||
|             return false; | ||||
|         } | ||||
| 
 | ||||
|         if (strpos($exception->getMessage(), 'LockableFile') !== false) { | ||||
|             return false; | ||||
|         } | ||||
| 
 | ||||
|         return true; | ||||
|     } | ||||
| @ -168,11 +170,11 @@ class Handler extends ExceptionHandler | ||||
|     { | ||||
|         if ($exception instanceof ModelNotFoundException && $request->expectsJson()) { | ||||
|             return response()->json(['message'=>$exception->getMessage()], 400); | ||||
|         }elseif($exception instanceof InternalPDFFailure && $request->expectsJson()){ | ||||
|         } elseif ($exception instanceof InternalPDFFailure && $request->expectsJson()) { | ||||
|             return response()->json(['message' => $exception->getMessage()], 500); | ||||
|         }elseif($exception instanceof PhantomPDFFailure && $request->expectsJson()){ | ||||
|         } elseif ($exception instanceof PhantomPDFFailure && $request->expectsJson()) { | ||||
|             return response()->json(['message' => $exception->getMessage()], 500); | ||||
|         }elseif($exception instanceof FilePermissionsFailure) { | ||||
|         } elseif ($exception instanceof FilePermissionsFailure) { | ||||
|             return response()->json(['message' => $exception->getMessage()], 500); | ||||
|         } elseif ($exception instanceof ThrottleRequestsException && $request->expectsJson()) { | ||||
|             return response()->json(['message'=>'Too many requests'], 429); | ||||
| @ -202,7 +204,7 @@ class Handler extends ExceptionHandler | ||||
|             return response()->json(['message' => $exception->getMessage()], 400); | ||||
|         } elseif ($exception instanceof StripeConnectFailure) { | ||||
|             return response()->json(['message' => $exception->getMessage()], 400); | ||||
|         }  | ||||
|         } | ||||
| 
 | ||||
|         return parent::render($request, $exception); | ||||
|     } | ||||
|  | ||||
| @ -14,6 +14,7 @@ class PaymentFailed extends Exception | ||||
|     public function render($request) | ||||
|     { | ||||
|         if (auth()->guard('contact')->user() || ($request->has('cko-session-id') && $request->query('cko-session-id') )) { | ||||
| 
 | ||||
|             return render('gateways.unsuccessful', [ | ||||
|                 'message' => $this->getMessage(), | ||||
|                 'code' => $this->getCode(), | ||||
|  | ||||
| @ -30,12 +30,12 @@ class PaymentRefundFailed extends Exception | ||||
|         // $msg = 'Unable to refund the transaction';
 | ||||
|         $msg = ctrans('texts.warning_local_refund'); | ||||
| 
 | ||||
|         if($this->getMessage() && strlen($this->getMessage()) >=1 ) | ||||
|         if ($this->getMessage() && strlen($this->getMessage()) >= 1) { | ||||
|             $msg = $this->getMessage(); | ||||
|         } | ||||
| 
 | ||||
|         return response()->json([ | ||||
|            'message' => $msg, | ||||
|        ], 401); | ||||
| 
 | ||||
|             'message' => $msg, | ||||
|         ], 401); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -13,12 +13,9 @@ class SystemError extends Exception | ||||
| 
 | ||||
|     public function render($request) | ||||
|     { | ||||
| 
 | ||||
|         return view('errors.guest', [ | ||||
|             'message' => $this->getMessage(), | ||||
|             'code' => $this->getCode(), | ||||
|         ]); | ||||
|          | ||||
| 
 | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -15,28 +15,22 @@ use Illuminate\Support\Carbon; | ||||
| 
 | ||||
| class BaseExport | ||||
| { | ||||
| 
 | ||||
|     protected function addDateRange($query) | ||||
|     { | ||||
| 
 | ||||
|         $date_range = $this->input['date_range']; | ||||
| 
 | ||||
|         if(array_key_exists('date_key', $this->input) && strlen($this->input['date_key']) > 1) | ||||
|         if (array_key_exists('date_key', $this->input) && strlen($this->input['date_key']) > 1) { | ||||
|             $this->date_key = $this->input['date_key']; | ||||
|          | ||||
|         try{ | ||||
| 
 | ||||
|             $custom_start_date = Carbon::parse($this->input['start_date']); | ||||
|             $custom_end_date = Carbon::parse($this->input['end_date']);     | ||||
| 
 | ||||
|         } | ||||
|         catch(\Exception $e){ | ||||
| 
 | ||||
|         try { | ||||
|             $custom_start_date = Carbon::parse($this->input['start_date']); | ||||
|             $custom_end_date = Carbon::parse($this->input['end_date']); | ||||
|         } catch (\Exception $e) { | ||||
|             $custom_start_date = now()->startOfYear(); | ||||
|             $custom_end_date = now(); | ||||
| 
 | ||||
|         } | ||||
|          | ||||
| 
 | ||||
|         switch ($date_range) { | ||||
| 
 | ||||
|             case 'all': | ||||
| @ -61,26 +55,23 @@ class BaseExport | ||||
|                 return $query->whereBetween($this->date_key, [now()->startOfYear(), now()])->orderBy($this->date_key, 'ASC'); | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     protected function buildHeader() :array | ||||
|     { | ||||
| 
 | ||||
|         $header = []; | ||||
| 
 | ||||
|         foreach($this->input['report_keys'] as $value){ | ||||
|         foreach ($this->input['report_keys'] as $value) { | ||||
|             $key = array_search($value, $this->entity_keys); | ||||
| 
 | ||||
|             $key = array_search ($value, $this->entity_keys); | ||||
|              | ||||
|             $key = str_replace("item.", "", $key); | ||||
|             $key = str_replace("invoice.", "", $key); | ||||
|             $key = str_replace("client.", "", $key); | ||||
|             $key = str_replace("contact.", "", $key); | ||||
|             $key = str_replace('item.', '', $key); | ||||
|             $key = str_replace('invoice.', '', $key); | ||||
|             $key = str_replace('client.', '', $key); | ||||
|             $key = str_replace('contact.', '', $key); | ||||
| 
 | ||||
|             $header[] = ctrans("texts.{$key}"); | ||||
|         } | ||||
| 
 | ||||
|         return $header; | ||||
|     } | ||||
| } | ||||
| } | ||||
|  | ||||
| @ -17,9 +17,9 @@ use App\Models\Company; | ||||
| use App\Transformers\ClientContactTransformer; | ||||
| use App\Transformers\ClientTransformer; | ||||
| use App\Utils\Ninja; | ||||
| use Illuminate\Support\Carbon; | ||||
| use Illuminate\Support\Facades\App; | ||||
| use League\Csv\Writer; | ||||
| use Illuminate\Support\Carbon; | ||||
| 
 | ||||
| class ClientExport extends BaseExport | ||||
| { | ||||
| @ -95,7 +95,6 @@ class ClientExport extends BaseExport | ||||
| 
 | ||||
|     public function run() | ||||
|     { | ||||
| 
 | ||||
|         MultiDB::setDb($this->company->db); | ||||
|         App::forgetInstance('translator'); | ||||
|         App::setLocale($this->company->locale()); | ||||
| @ -105,8 +104,9 @@ class ClientExport extends BaseExport | ||||
|         //load the CSV document from a string
 | ||||
|         $this->csv = Writer::createFromString(); | ||||
| 
 | ||||
|         if(count($this->input['report_keys']) == 0) | ||||
|         if (count($this->input['report_keys']) == 0) { | ||||
|             $this->input['report_keys'] = array_values($this->entity_keys); | ||||
|         } | ||||
| 
 | ||||
|         //insert the header
 | ||||
|         $this->csv->insertOne($this->buildHeader()); | ||||
| @ -114,69 +114,65 @@ class ClientExport extends BaseExport | ||||
|         $query = Client::query()->with('contacts') | ||||
|                                 ->withTrashed() | ||||
|                                 ->where('company_id', $this->company->id) | ||||
|                                 ->where('is_deleted',0); | ||||
|      | ||||
|                                 ->where('is_deleted', 0); | ||||
| 
 | ||||
|         $query = $this->addDateRange($query); | ||||
| 
 | ||||
|         $query->cursor() | ||||
|               ->each(function ($client){ | ||||
|                         $this->csv->insertOne($this->buildRow($client));  | ||||
|                     }); | ||||
| 
 | ||||
| 
 | ||||
|         return $this->csv->toString();  | ||||
|               ->each(function ($client) { | ||||
|                   $this->csv->insertOne($this->buildRow($client)); | ||||
|               }); | ||||
| 
 | ||||
|         return $this->csv->toString(); | ||||
|     } | ||||
| 
 | ||||
|     private function buildRow(Client $client) :array | ||||
|     { | ||||
| 
 | ||||
|         $transformed_contact = false; | ||||
| 
 | ||||
|         $transformed_client = $this->client_transformer->transform($client); | ||||
| 
 | ||||
|         if($contact = $client->contacts()->first()) | ||||
|         if ($contact = $client->contacts()->first()) { | ||||
|             $transformed_contact = $this->contact_transformer->transform($contact); | ||||
|         } | ||||
| 
 | ||||
|         $entity = []; | ||||
| 
 | ||||
|         foreach(array_values($this->input['report_keys']) as $key){ | ||||
|         foreach (array_values($this->input['report_keys']) as $key) { | ||||
|             $parts = explode('.', $key); | ||||
| 
 | ||||
|             $parts = explode(".",$key); | ||||
|              | ||||
|             $keyval = array_search($key, $this->entity_keys); | ||||
| 
 | ||||
|             if($parts[0] == 'client' && array_key_exists($parts[1], $transformed_client)) { | ||||
|             if ($parts[0] == 'client' && array_key_exists($parts[1], $transformed_client)) { | ||||
|                 $entity[$keyval] = $transformed_client[$parts[1]]; | ||||
|             } | ||||
|             elseif($parts[0] == 'contact' && array_key_exists($parts[1], $transformed_contact)) { | ||||
|             } elseif ($parts[0] == 'contact' && array_key_exists($parts[1], $transformed_contact)) { | ||||
|                 $entity[$keyval] = $transformed_contact[$parts[1]]; | ||||
|             } else { | ||||
|                 $entity[$keyval] = ''; | ||||
|             } | ||||
|             else  | ||||
|                 $entity[$keyval] = ""; | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         return $this->decorateAdvancedFields($client, $entity); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private function decorateAdvancedFields(Client $client, array $entity) :array | ||||
|     { | ||||
|         if (in_array('client.country_id', $this->input['report_keys'])) { | ||||
|             $entity['country'] = $client->country ? ctrans("texts.country_{$client->country->name}") : ''; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('client.country_id', $this->input['report_keys'])) | ||||
|             $entity['country'] = $client->country ? ctrans("texts.country_{$client->country->name}") : "";  | ||||
|         if (in_array('client.shipping_country_id', $this->input['report_keys'])) { | ||||
|             $entity['shipping_country'] = $client->shipping_country ? ctrans("texts.country_{$client->shipping_country->name}") : ''; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('client.shipping_country_id', $this->input['report_keys'])) | ||||
|             $entity['shipping_country'] = $client->shipping_country ? ctrans("texts.country_{$client->shipping_country->name}") : "";  | ||||
| 
 | ||||
|         if(in_array('client.currency', $this->input['report_keys'])) | ||||
|         if (in_array('client.currency', $this->input['report_keys'])) { | ||||
|             $entity['currency'] = $client->currency() ? $client->currency()->code : $client->company->currency()->code; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('client.industry_id', $this->input['report_keys'])) | ||||
|             $entity['industry_id'] = $client->industry ? ctrans("texts.industry_{$client->industry->name}") : "";  | ||||
|         if (in_array('client.industry_id', $this->input['report_keys'])) { | ||||
|             $entity['industry_id'] = $client->industry ? ctrans("texts.industry_{$client->industry->name}") : ''; | ||||
|         } | ||||
| 
 | ||||
|         return $entity; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -91,7 +91,6 @@ class ContactExport extends BaseExport | ||||
| 
 | ||||
|     public function run() | ||||
|     { | ||||
| 
 | ||||
|         MultiDB::setDb($this->company->db); | ||||
|         App::forgetInstance('translator'); | ||||
|         App::setLocale($this->company->locale()); | ||||
| @ -101,8 +100,9 @@ class ContactExport extends BaseExport | ||||
|         //load the CSV document from a string
 | ||||
|         $this->csv = Writer::createFromString(); | ||||
| 
 | ||||
|         if(count($this->input['report_keys']) == 0) | ||||
|         if (count($this->input['report_keys']) == 0) { | ||||
|             $this->input['report_keys'] = array_values($this->entity_keys); | ||||
|         } | ||||
| 
 | ||||
|         //insert the header
 | ||||
|         $this->csv->insertOne($this->buildHeader()); | ||||
| @ -112,19 +112,15 @@ class ContactExport extends BaseExport | ||||
| 
 | ||||
|         $query = $this->addDateRange($query); | ||||
| 
 | ||||
|         $query->cursor()->each(function ($contact){ | ||||
| 
 | ||||
|             $this->csv->insertOne($this->buildRow($contact));  | ||||
| 
 | ||||
|         $query->cursor()->each(function ($contact) { | ||||
|             $this->csv->insertOne($this->buildRow($contact)); | ||||
|         }); | ||||
| 
 | ||||
|         return $this->csv->toString();  | ||||
| 
 | ||||
|         return $this->csv->toString(); | ||||
|     } | ||||
| 
 | ||||
|     private function buildRow(ClientContact $contact) :array | ||||
|     { | ||||
| 
 | ||||
|         $transformed_contact = false; | ||||
| 
 | ||||
|         $transformed_client = $this->client_transformer->transform($contact->client); | ||||
| @ -132,41 +128,40 @@ class ContactExport extends BaseExport | ||||
| 
 | ||||
|         $entity = []; | ||||
| 
 | ||||
|         foreach(array_values($this->input['report_keys']) as $key){ | ||||
| 
 | ||||
|             $parts = explode(".",$key); | ||||
|         foreach (array_values($this->input['report_keys']) as $key) { | ||||
|             $parts = explode('.', $key); | ||||
|             $keyval = array_search($key, $this->entity_keys); | ||||
| 
 | ||||
|             if($parts[0] == 'client' && array_key_exists($parts[1], $transformed_client)) { | ||||
|             if ($parts[0] == 'client' && array_key_exists($parts[1], $transformed_client)) { | ||||
|                 $entity[$keyval] = $transformed_client[$parts[1]]; | ||||
|             } | ||||
|             elseif($parts[0] == 'contact' && array_key_exists($parts[1], $transformed_contact)) { | ||||
|             } elseif ($parts[0] == 'contact' && array_key_exists($parts[1], $transformed_contact)) { | ||||
|                 $entity[$keyval] = $transformed_contact[$parts[1]]; | ||||
|             } else { | ||||
|                 $entity[$keyval] = ''; | ||||
|             } | ||||
|             else  | ||||
|                 $entity[$keyval] = ""; | ||||
|         } | ||||
| 
 | ||||
|         return $this->decorateAdvancedFields($contact->client, $entity); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private function decorateAdvancedFields(Client $client, array $entity) :array | ||||
|     { | ||||
|         if (in_array('client.country_id', $this->input['report_keys'])) { | ||||
|             $entity['country'] = $client->country ? ctrans("texts.country_{$client->country->name}") : ''; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('client.country_id', $this->input['report_keys'])) | ||||
|             $entity['country'] = $client->country ? ctrans("texts.country_{$client->country->name}") : "";  | ||||
|         if (in_array('client.shipping_country_id', $this->input['report_keys'])) { | ||||
|             $entity['shipping_country'] = $client->shipping_country ? ctrans("texts.country_{$client->shipping_country->name}") : ''; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('client.shipping_country_id', $this->input['report_keys'])) | ||||
|             $entity['shipping_country'] = $client->shipping_country ? ctrans("texts.country_{$client->shipping_country->name}") : "";  | ||||
| 
 | ||||
|         if(in_array('client.currency', $this->input['report_keys'])) | ||||
|         if (in_array('client.currency', $this->input['report_keys'])) { | ||||
|             $entity['currency'] = $client->currency() ? $client->currency()->code : $client->company->currency()->code; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('client.industry_id', $this->input['report_keys'])) | ||||
|             $entity['industry_id'] = $client->industry ? ctrans("texts.industry_{$client->industry->name}") : "";  | ||||
|         if (in_array('client.industry_id', $this->input['report_keys'])) { | ||||
|             $entity['industry_id'] = $client->industry ? ctrans("texts.industry_{$client->industry->name}") : ''; | ||||
|         } | ||||
| 
 | ||||
|         return $entity; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -65,7 +65,7 @@ class CreditExport extends BaseExport | ||||
|         'tax_rate3' => 'tax_rate3', | ||||
|         'terms' => 'terms', | ||||
|         'total_taxes' => 'total_taxes', | ||||
|         'currency' => 'currency' | ||||
|         'currency' => 'currency', | ||||
|     ]; | ||||
| 
 | ||||
|     private array $decorate_keys = [ | ||||
| @ -84,7 +84,6 @@ class CreditExport extends BaseExport | ||||
| 
 | ||||
|     public function run() | ||||
|     { | ||||
| 
 | ||||
|         MultiDB::setDb($this->company->db); | ||||
|         App::forgetInstance('translator'); | ||||
|         App::setLocale($this->company->locale()); | ||||
| @ -94,71 +93,69 @@ class CreditExport extends BaseExport | ||||
|         //load the CSV document from a string
 | ||||
|         $this->csv = Writer::createFromString(); | ||||
| 
 | ||||
|         if(count($this->input['report_keys']) == 0) | ||||
|         if (count($this->input['report_keys']) == 0) { | ||||
|             $this->input['report_keys'] = array_values($this->entity_keys); | ||||
|          | ||||
|         } | ||||
| 
 | ||||
|         //insert the header
 | ||||
|         $this->csv->insertOne($this->buildHeader()); | ||||
| 
 | ||||
|         $query = Credit::query() | ||||
|                         ->withTrashed() | ||||
|                         ->with('client')->where('company_id', $this->company->id) | ||||
|                         ->where('is_deleted',0); | ||||
|                         ->where('is_deleted', 0); | ||||
| 
 | ||||
|         $query = $this->addDateRange($query); | ||||
| 
 | ||||
|         $query->cursor() | ||||
|             ->each(function ($credit){ | ||||
| 
 | ||||
|                 $this->csv->insertOne($this->buildRow($credit));  | ||||
| 
 | ||||
|         }); | ||||
| 
 | ||||
|         return $this->csv->toString();  | ||||
|             ->each(function ($credit) { | ||||
|                 $this->csv->insertOne($this->buildRow($credit)); | ||||
|             }); | ||||
| 
 | ||||
|         return $this->csv->toString(); | ||||
|     } | ||||
| 
 | ||||
|     private function buildRow(Credit $credit) :array | ||||
|     { | ||||
| 
 | ||||
|         $transformed_credit = $this->credit_transformer->transform($credit); | ||||
| 
 | ||||
|         $entity = []; | ||||
| 
 | ||||
|         foreach(array_values($this->input['report_keys']) as $key){ | ||||
| 
 | ||||
|         foreach (array_values($this->input['report_keys']) as $key) { | ||||
|             $keyval = array_search($key, $this->entity_keys); | ||||
| 
 | ||||
|             if(array_key_exists($key, $transformed_credit)) | ||||
|             if (array_key_exists($key, $transformed_credit)) { | ||||
|                 $entity[$keyval] = $transformed_credit[$key]; | ||||
|             else | ||||
|             } else { | ||||
|                 $entity[$keyval] = ''; | ||||
| 
 | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return $this->decorateAdvancedFields($credit, $entity); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private function decorateAdvancedFields(Credit $credit, array $entity) :array | ||||
|     { | ||||
|         if (in_array('country_id', $this->input['report_keys'])) { | ||||
|             $entity['country'] = $credit->client->country ? ctrans("texts.country_{$credit->client->country->name}") : ''; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('country_id', $this->input['report_keys'])) | ||||
|             $entity['country'] = $credit->client->country ? ctrans("texts.country_{$credit->client->country->name}") : "";  | ||||
|         if (in_array('currency_id', $this->input['report_keys'])) { | ||||
|             $entity['currency_id'] = $credit->client->currency() ? $credit->client->currency()->code : $invoice->company->currency()->code; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('currency_id', $this->input['report_keys'])) | ||||
|             $entity['currency_id'] = $credit->client->currency() ? $credit->client->currency()->code : $invoice->company->currency()->code;; | ||||
|         if (in_array('invoice_id', $this->input['report_keys'])) { | ||||
|             $entity['invoice'] = $credit->invoice ? $credit->invoice->number : ''; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('invoice_id', $this->input['report_keys'])) | ||||
|             $entity['invoice'] = $credit->invoice ? $credit->invoice->number : ""; | ||||
| 
 | ||||
|         if(in_array('client_id', $this->input['report_keys'])) | ||||
|         if (in_array('client_id', $this->input['report_keys'])) { | ||||
|             $entity['client'] = $credit->client->present()->name(); | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('status_id',$this->input['report_keys'])) | ||||
|         if (in_array('status_id', $this->input['report_keys'])) { | ||||
|             $entity['status'] = $credit->stringStatus($credit->status_id); | ||||
|         } | ||||
| 
 | ||||
|         return $entity; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -52,7 +52,6 @@ class DocumentExport extends BaseExport | ||||
| 
 | ||||
|     public function run() | ||||
|     { | ||||
| 
 | ||||
|         MultiDB::setDb($this->company->db); | ||||
|         App::forgetInstance('translator'); | ||||
|         App::setLocale($this->company->locale()); | ||||
| @ -62,8 +61,9 @@ class DocumentExport extends BaseExport | ||||
|         //load the CSV document from a string
 | ||||
|         $this->csv = Writer::createFromString(); | ||||
| 
 | ||||
|         if(count($this->input['report_keys']) == 0) | ||||
|         if (count($this->input['report_keys']) == 0) { | ||||
|             $this->input['report_keys'] = array_values($this->entity_keys); | ||||
|         } | ||||
| 
 | ||||
|         //insert the header
 | ||||
|         $this->csv->insertOne($this->buildHeader()); | ||||
| @ -73,47 +73,41 @@ class DocumentExport extends BaseExport | ||||
|         $query = $this->addDateRange($query); | ||||
| 
 | ||||
|         $query->cursor() | ||||
|               ->each(function ($entity){ | ||||
| 
 | ||||
|             $this->csv->insertOne($this->buildRow($entity));  | ||||
| 
 | ||||
|         }); | ||||
| 
 | ||||
|         return $this->csv->toString();  | ||||
|               ->each(function ($entity) { | ||||
|                   $this->csv->insertOne($this->buildRow($entity)); | ||||
|               }); | ||||
| 
 | ||||
|         return $this->csv->toString(); | ||||
|     } | ||||
| 
 | ||||
|     private function buildRow(Document $document) :array | ||||
|     { | ||||
| 
 | ||||
|         $transformed_entity = $this->entity_transformer->transform($document); | ||||
| 
 | ||||
|         $entity = []; | ||||
| 
 | ||||
|         foreach(array_values($this->input['report_keys']) as $key){ | ||||
| 
 | ||||
|         foreach (array_values($this->input['report_keys']) as $key) { | ||||
|             $keyval = array_search($key, $this->entity_keys); | ||||
| 
 | ||||
|             if(array_key_exists($key, $transformed_entity)) | ||||
|             if (array_key_exists($key, $transformed_entity)) { | ||||
|                 $entity[$keyval] = $transformed_entity[$key]; | ||||
|             else | ||||
|                 $entity[$keyval] = '';         | ||||
|             } else { | ||||
|                 $entity[$keyval] = ''; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return $this->decorateAdvancedFields($document, $entity); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private function decorateAdvancedFields(Document $document, array $entity) :array | ||||
|     { | ||||
| 
 | ||||
|         if(in_array('record_type', $this->input['report_keys'])) | ||||
|         if (in_array('record_type', $this->input['report_keys'])) { | ||||
|             $entity['record_type'] = class_basename($document->documentable); | ||||
|         } | ||||
| 
 | ||||
|         // if(in_array('record_name', $this->input['report_keys']))
 | ||||
|         //     $entity['record_name'] = $document->hashed_id;
 | ||||
| 
 | ||||
|         return $entity; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -82,7 +82,6 @@ class ExpenseExport extends BaseExport | ||||
| 
 | ||||
|     public function run() | ||||
|     { | ||||
| 
 | ||||
|         MultiDB::setDb($this->company->db); | ||||
|         App::forgetInstance('translator'); | ||||
|         App::setLocale($this->company->locale()); | ||||
| @ -92,8 +91,9 @@ class ExpenseExport extends BaseExport | ||||
|         //load the CSV document from a string
 | ||||
|         $this->csv = Writer::createFromString(); | ||||
| 
 | ||||
|         if(count($this->input['report_keys']) == 0) | ||||
|         if (count($this->input['report_keys']) == 0) { | ||||
|             $this->input['report_keys'] = array_values($this->entity_keys); | ||||
|         } | ||||
| 
 | ||||
|         //insert the header
 | ||||
|         $this->csv->insertOne($this->buildHeader()); | ||||
| @ -102,69 +102,67 @@ class ExpenseExport extends BaseExport | ||||
|                         ->with('client') | ||||
|                         ->withTrashed() | ||||
|                         ->where('company_id', $this->company->id) | ||||
|                         ->where('is_deleted',0); | ||||
|                         ->where('is_deleted', 0); | ||||
| 
 | ||||
|         $query = $this->addDateRange($query); | ||||
| 
 | ||||
|         $query->cursor() | ||||
|                 ->each(function ($expense){ | ||||
| 
 | ||||
|                     $this->csv->insertOne($this->buildRow($expense));  | ||||
| 
 | ||||
|         }); | ||||
| 
 | ||||
| 
 | ||||
|         return $this->csv->toString();  | ||||
|                 ->each(function ($expense) { | ||||
|                     $this->csv->insertOne($this->buildRow($expense)); | ||||
|                 }); | ||||
| 
 | ||||
|         return $this->csv->toString(); | ||||
|     } | ||||
| 
 | ||||
|     private function buildRow(Expense $expense) :array | ||||
|     { | ||||
| 
 | ||||
|         $transformed_expense = $this->expense_transformer->transform($expense); | ||||
| 
 | ||||
|         $entity = []; | ||||
| 
 | ||||
|         foreach(array_values($this->input['report_keys']) as $key){ | ||||
| 
 | ||||
|         foreach (array_values($this->input['report_keys']) as $key) { | ||||
|             $keyval = array_search($key, $this->entity_keys); | ||||
| 
 | ||||
|             if(array_key_exists($key, $transformed_expense)) | ||||
|             if (array_key_exists($key, $transformed_expense)) { | ||||
|                 $entity[$keyval] = $transformed_expense[$key]; | ||||
|             else | ||||
|             } else { | ||||
|                 $entity[$keyval] = ''; | ||||
| 
 | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return $this->decorateAdvancedFields($expense, $entity); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private function decorateAdvancedFields(Expense $expense, array $entity) :array | ||||
|     { | ||||
|         if(in_array('currency_id', $this->input['report_keys'])) | ||||
|             $entity['currency'] = $expense->currency ? $expense->currency->code : ""; | ||||
|         if (in_array('currency_id', $this->input['report_keys'])) { | ||||
|             $entity['currency'] = $expense->currency ? $expense->currency->code : ''; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('client_id', $this->input['report_keys'])) | ||||
|             $entity['client'] = $expense->client ? $expense->client->present()->name() : ""; | ||||
|         if (in_array('client_id', $this->input['report_keys'])) { | ||||
|             $entity['client'] = $expense->client ? $expense->client->present()->name() : ''; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('invoice_id', $this->input['report_keys'])) | ||||
|             $entity['invoice'] = $expense->invoice ? $expense->invoice->number : ""; | ||||
|         if (in_array('invoice_id', $this->input['report_keys'])) { | ||||
|             $entity['invoice'] = $expense->invoice ? $expense->invoice->number : ''; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('category_id', $this->input['report_keys'])) | ||||
|             $entity['category'] = $expense->category ? $expense->category->name : ""; | ||||
|         if (in_array('category_id', $this->input['report_keys'])) { | ||||
|             $entity['category'] = $expense->category ? $expense->category->name : ''; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('vendor_id', $this->input['report_keys'])) | ||||
|             $entity['vendor'] = $expense->vendor ? $expense->vendor->name : ""; | ||||
|         if (in_array('vendor_id', $this->input['report_keys'])) { | ||||
|             $entity['vendor'] = $expense->vendor ? $expense->vendor->name : ''; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('payment_type_id', $this->input['report_keys'])) | ||||
|             $entity['payment_type'] = $expense->payment_type ? $expense->payment_type->name : ""; | ||||
| 
 | ||||
|         if(in_array('project_id', $this->input['report_keys'])) | ||||
|             $entity['project'] = $expense->project ? $expense->project->name : ""; | ||||
|         if (in_array('payment_type_id', $this->input['report_keys'])) { | ||||
|             $entity['payment_type'] = $expense->payment_type ? $expense->payment_type->name : ''; | ||||
|         } | ||||
| 
 | ||||
|         if (in_array('project_id', $this->input['report_keys'])) { | ||||
|             $entity['project'] = $expense->project ? $expense->project->name : ''; | ||||
|         } | ||||
| 
 | ||||
|         return $entity; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -63,7 +63,7 @@ class InvoiceExport extends BaseExport | ||||
|         'tax_rate3' => 'tax_rate3', | ||||
|         'terms' => 'terms', | ||||
|         'total_taxes' => 'total_taxes', | ||||
|         'currency_id' => 'currency_id' | ||||
|         'currency_id' => 'currency_id', | ||||
|     ]; | ||||
| 
 | ||||
|     private array $decorate_keys = [ | ||||
| @ -84,7 +84,6 @@ class InvoiceExport extends BaseExport | ||||
| 
 | ||||
|     public function run() | ||||
|     { | ||||
| 
 | ||||
|         MultiDB::setDb($this->company->db); | ||||
|         App::forgetInstance('translator'); | ||||
|         App::setLocale($this->company->locale()); | ||||
| @ -94,9 +93,10 @@ class InvoiceExport extends BaseExport | ||||
|         //load the CSV document from a string
 | ||||
|         $this->csv = Writer::createFromString(); | ||||
| 
 | ||||
|         if(count($this->input['report_keys']) == 0) | ||||
|         if (count($this->input['report_keys']) == 0) { | ||||
|             $this->input['report_keys'] = array_values($this->entity_keys); | ||||
|          | ||||
|         } | ||||
| 
 | ||||
|         //insert the header
 | ||||
|         $this->csv->insertOne($this->buildHeader()); | ||||
| 
 | ||||
| @ -104,57 +104,55 @@ class InvoiceExport extends BaseExport | ||||
|                         ->withTrashed() | ||||
|                         ->with('client') | ||||
|                         ->where('company_id', $this->company->id) | ||||
|                         ->where('is_deleted',0); | ||||
|                         ->where('is_deleted', 0); | ||||
| 
 | ||||
|         $query = $this->addDateRange($query); | ||||
| 
 | ||||
|         $query->cursor() | ||||
|             ->each(function ($invoice){ | ||||
| 
 | ||||
|                 $this->csv->insertOne($this->buildRow($invoice));  | ||||
| 
 | ||||
|         }); | ||||
| 
 | ||||
|         return $this->csv->toString();  | ||||
|             ->each(function ($invoice) { | ||||
|                 $this->csv->insertOne($this->buildRow($invoice)); | ||||
|             }); | ||||
| 
 | ||||
|         return $this->csv->toString(); | ||||
|     } | ||||
| 
 | ||||
|     private function buildRow(Invoice $invoice) :array | ||||
|     { | ||||
| 
 | ||||
|         $transformed_invoice = $this->invoice_transformer->transform($invoice); | ||||
| 
 | ||||
|         $entity = []; | ||||
| 
 | ||||
|         foreach(array_values($this->input['report_keys']) as $key){ | ||||
| 
 | ||||
|         foreach (array_values($this->input['report_keys']) as $key) { | ||||
|             $keyval = array_search($key, $this->entity_keys); | ||||
| 
 | ||||
|             if(array_key_exists($key, $transformed_invoice)) | ||||
|             if (array_key_exists($key, $transformed_invoice)) { | ||||
|                 $entity[$keyval] = $transformed_invoice[$key]; | ||||
|             else | ||||
|             } else { | ||||
|                 $entity[$keyval] = ''; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return $this->decorateAdvancedFields($invoice, $entity); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private function decorateAdvancedFields(Invoice $invoice, array $entity) :array | ||||
|     { | ||||
|         if(in_array('country_id', $this->input['report_keys'])) | ||||
|             $entity['country'] = $invoice->client->country ? ctrans("texts.country_{$invoice->client->country->name}") : "";  | ||||
|         if (in_array('country_id', $this->input['report_keys'])) { | ||||
|             $entity['country'] = $invoice->client->country ? ctrans("texts.country_{$invoice->client->country->name}") : ''; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('currency_id', $this->input['report_keys'])) | ||||
|         if (in_array('currency_id', $this->input['report_keys'])) { | ||||
|             $entity['currency_id'] = $invoice->client->currency() ? $invoice->client->currency()->code : $invoice->company->currency()->code; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('client_id', $this->input['report_keys'])) | ||||
|         if (in_array('client_id', $this->input['report_keys'])) { | ||||
|             $entity['client'] = $invoice->client->present()->name(); | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('status_id',$this->input['report_keys'])) | ||||
|         if (in_array('status_id', $this->input['report_keys'])) { | ||||
|             $entity['status'] = $invoice->stringStatus($invoice->status_id); | ||||
|         } | ||||
| 
 | ||||
|         return $entity; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -73,7 +73,6 @@ class PaymentExport extends BaseExport | ||||
| 
 | ||||
|     public function run() | ||||
|     { | ||||
| 
 | ||||
|         MultiDB::setDb($this->company->db); | ||||
|         App::forgetInstance('translator'); | ||||
|         App::setLocale($this->company->locale()); | ||||
| @ -83,8 +82,9 @@ class PaymentExport extends BaseExport | ||||
|         //load the CSV document from a string
 | ||||
|         $this->csv = Writer::createFromString(); | ||||
| 
 | ||||
|         if(count($this->input['report_keys']) == 0) | ||||
|         if (count($this->input['report_keys']) == 0) { | ||||
|             $this->input['report_keys'] = array_values($this->entity_keys); | ||||
|         } | ||||
| 
 | ||||
|         //insert the header
 | ||||
|         $this->csv->insertOne($this->buildHeader()); | ||||
| @ -94,66 +94,66 @@ class PaymentExport extends BaseExport | ||||
|         $query = $this->addDateRange($query); | ||||
| 
 | ||||
|         $query->cursor() | ||||
|               ->each(function ($entity){ | ||||
| 
 | ||||
|             $this->csv->insertOne($this->buildRow($entity));  | ||||
| 
 | ||||
|         }); | ||||
| 
 | ||||
|         return $this->csv->toString();  | ||||
|               ->each(function ($entity) { | ||||
|                   $this->csv->insertOne($this->buildRow($entity)); | ||||
|               }); | ||||
| 
 | ||||
|         return $this->csv->toString(); | ||||
|     } | ||||
| 
 | ||||
|     private function buildRow(Payment $payment) :array | ||||
|     { | ||||
| 
 | ||||
|         $transformed_entity = $this->entity_transformer->transform($payment); | ||||
| 
 | ||||
|         $entity = []; | ||||
| 
 | ||||
|         foreach(array_values($this->input['report_keys']) as $key){ | ||||
| 
 | ||||
|         foreach (array_values($this->input['report_keys']) as $key) { | ||||
|             $keyval = array_search($key, $this->entity_keys); | ||||
| 
 | ||||
|             if(array_key_exists($key, $transformed_entity)) | ||||
|             if (array_key_exists($key, $transformed_entity)) { | ||||
|                 $entity[$keyval] = $transformed_entity[$key]; | ||||
|             else | ||||
|             } else { | ||||
|                 $entity[$keyval] = ''; | ||||
|          | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return $this->decorateAdvancedFields($payment, $entity); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private function decorateAdvancedFields(Payment $payment, array $entity) :array | ||||
|     { | ||||
| 
 | ||||
|         if(in_array('status_id', $this->input['report_keys'])) | ||||
|         if (in_array('status_id', $this->input['report_keys'])) { | ||||
|             $entity['status'] = $payment->stringStatus($payment->status_id); | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('vendor_id', $this->input['report_keys'])) | ||||
|         if (in_array('vendor_id', $this->input['report_keys'])) { | ||||
|             $entity['vendor'] = $payment->vendor()->exists() ? $payment->vendor->name : ''; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('project_id', $this->input['report_keys'])) | ||||
|         if (in_array('project_id', $this->input['report_keys'])) { | ||||
|             $entity['project'] = $payment->project()->exists() ? $payment->project->name : ''; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('currency_id', $this->input['report_keys'])) | ||||
|         if (in_array('currency_id', $this->input['report_keys'])) { | ||||
|             $entity['currency'] = $payment->currency()->exists() ? $payment->currency->code : ''; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('exchange_currency_id', $this->input['report_keys'])) | ||||
|         if (in_array('exchange_currency_id', $this->input['report_keys'])) { | ||||
|             $entity['exchange_currency'] = $payment->exchange_currency()->exists() ? $payment->exchange_currency->code : ''; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('client_id', $this->input['report_keys'])) | ||||
|         if (in_array('client_id', $this->input['report_keys'])) { | ||||
|             $entity['client'] = $payment->client->present()->name(); | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('type_id', $this->input['report_keys'])) | ||||
|         if (in_array('type_id', $this->input['report_keys'])) { | ||||
|             $entity['type'] = $payment->translatedType(); | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('gateway_type_id', $this->input['report_keys'])) | ||||
|             $entity['gateway'] = $payment->gateway_type ? $payment->gateway_type->name : "Unknown Type"; | ||||
|         if (in_array('gateway_type_id', $this->input['report_keys'])) { | ||||
|             $entity['gateway'] = $payment->gateway_type ? $payment->gateway_type->name : 'Unknown Type'; | ||||
|         } | ||||
| 
 | ||||
|         return $entity; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -66,7 +66,6 @@ class ProductExport extends BaseExport | ||||
| 
 | ||||
|     public function run() | ||||
|     { | ||||
| 
 | ||||
|         MultiDB::setDb($this->company->db); | ||||
|         App::forgetInstance('translator'); | ||||
|         App::setLocale($this->company->locale()); | ||||
| @ -76,8 +75,9 @@ class ProductExport extends BaseExport | ||||
|         //load the CSV document from a string
 | ||||
|         $this->csv = Writer::createFromString(); | ||||
| 
 | ||||
|         if(count($this->input['report_keys']) == 0) | ||||
|         if (count($this->input['report_keys']) == 0) { | ||||
|             $this->input['report_keys'] = array_values($this->entity_keys); | ||||
|         } | ||||
| 
 | ||||
|         //insert the header
 | ||||
|         $this->csv->insertOne($this->buildHeader()); | ||||
| @ -87,49 +87,42 @@ class ProductExport extends BaseExport | ||||
|         $query = $this->addDateRange($query); | ||||
| 
 | ||||
|         $query->cursor() | ||||
|               ->each(function ($entity){ | ||||
| 
 | ||||
|             $this->csv->insertOne($this->buildRow($entity));  | ||||
| 
 | ||||
|         }); | ||||
| 
 | ||||
|         return $this->csv->toString();  | ||||
|               ->each(function ($entity) { | ||||
|                   $this->csv->insertOne($this->buildRow($entity)); | ||||
|               }); | ||||
| 
 | ||||
|         return $this->csv->toString(); | ||||
|     } | ||||
| 
 | ||||
|     private function buildRow(Product $product) :array | ||||
|     { | ||||
| 
 | ||||
|         $transformed_entity = $this->entity_transformer->transform($product); | ||||
| 
 | ||||
|         $entity = []; | ||||
| 
 | ||||
|         foreach(array_values($this->input['report_keys']) as $key){ | ||||
| 
 | ||||
|         foreach (array_values($this->input['report_keys']) as $key) { | ||||
|             $keyval = array_search($key, $this->entity_keys); | ||||
| 
 | ||||
|             if(array_key_exists($key, $transformed_entity)) | ||||
|             if (array_key_exists($key, $transformed_entity)) { | ||||
|                 $entity[$keyval] = $transformed_entity[$key]; | ||||
|             else | ||||
|             } else { | ||||
|                 $entity[$keyval] = ''; | ||||
|          | ||||
|          | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return $this->decorateAdvancedFields($product, $entity); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private function decorateAdvancedFields(Product $product, array $entity) :array | ||||
|     { | ||||
| 
 | ||||
|         if(in_array('vendor_id', $this->input['report_keys'])) | ||||
|         if (in_array('vendor_id', $this->input['report_keys'])) { | ||||
|             $entity['vendor'] = $product->vendor()->exists() ? $product->vendor->name : ''; | ||||
|         } | ||||
| 
 | ||||
|         if(array_key_exists('project_id', $this->input['report_keys'])) | ||||
|         if (array_key_exists('project_id', $this->input['report_keys'])) { | ||||
|             $entity['project'] = $product->project()->exists() ? $product->project->name : ''; | ||||
|         } | ||||
| 
 | ||||
|         return $entity; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -70,7 +70,7 @@ class QuoteExport extends BaseExport | ||||
|     private array $decorate_keys = [ | ||||
|         'client', | ||||
|         'currency', | ||||
|         'invoice' | ||||
|         'invoice', | ||||
|     ]; | ||||
| 
 | ||||
|     public function __construct(Company $company, array $input) | ||||
| @ -82,7 +82,6 @@ class QuoteExport extends BaseExport | ||||
| 
 | ||||
|     public function run() | ||||
|     { | ||||
| 
 | ||||
|         MultiDB::setDb($this->company->db); | ||||
|         App::forgetInstance('translator'); | ||||
|         App::setLocale($this->company->locale()); | ||||
| @ -92,8 +91,9 @@ class QuoteExport extends BaseExport | ||||
|         //load the CSV document from a string
 | ||||
|         $this->csv = Writer::createFromString(); | ||||
| 
 | ||||
|         if(count($this->input['report_keys']) == 0) | ||||
|         if (count($this->input['report_keys']) == 0) { | ||||
|             $this->input['report_keys'] = array_values($this->entity_keys); | ||||
|         } | ||||
| 
 | ||||
|         //insert the header
 | ||||
|         $this->csv->insertOne($this->buildHeader()); | ||||
| @ -101,58 +101,55 @@ class QuoteExport extends BaseExport | ||||
|         $query = Quote::query() | ||||
|                         ->with('client') | ||||
|                         ->where('company_id', $this->company->id) | ||||
|                         ->where('is_deleted',0); | ||||
|                         ->where('is_deleted', 0); | ||||
| 
 | ||||
|         $query = $this->addDateRange($query); | ||||
| 
 | ||||
|         $query->cursor() | ||||
|             ->each(function ($quote){ | ||||
| 
 | ||||
|                 $this->csv->insertOne($this->buildRow($quote));  | ||||
| 
 | ||||
|         }); | ||||
| 
 | ||||
| 
 | ||||
|         return $this->csv->toString();  | ||||
|             ->each(function ($quote) { | ||||
|                 $this->csv->insertOne($this->buildRow($quote)); | ||||
|             }); | ||||
| 
 | ||||
|         return $this->csv->toString(); | ||||
|     } | ||||
| 
 | ||||
|     private function buildRow(Quote $quote) :array | ||||
|     { | ||||
| 
 | ||||
|         $transformed_quote = $this->quote_transformer->transform($quote); | ||||
| 
 | ||||
|         $entity = []; | ||||
| 
 | ||||
|         foreach(array_values($this->input['report_keys']) as $key){ | ||||
| 
 | ||||
|         foreach (array_values($this->input['report_keys']) as $key) { | ||||
|             $keyval = array_search($key, $this->entity_keys); | ||||
| 
 | ||||
|             if(array_key_exists($key, $transformed_quote)) | ||||
|             if (array_key_exists($key, $transformed_quote)) { | ||||
|                 $entity[$keyval] = $transformed_quote[$key]; | ||||
|             else | ||||
|             } else { | ||||
|                 $entity[$keyval] = ''; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return $this->decorateAdvancedFields($quote, $entity); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private function decorateAdvancedFields(Quote $quote, array $entity) :array | ||||
|     { | ||||
|         if(in_array('currency_id', $this->input['report_keys'])) | ||||
|         if (in_array('currency_id', $this->input['report_keys'])) { | ||||
|             $entity['currency'] = $quote->client->currency()->code; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('client_id', $this->input['report_keys'])) | ||||
|         if (in_array('client_id', $this->input['report_keys'])) { | ||||
|             $entity['client'] = $quote->client->present()->name(); | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('status_id',$this->input['report_keys'])) | ||||
|         if (in_array('status_id', $this->input['report_keys'])) { | ||||
|             $entity['status'] = $quote->stringStatus($quote->status_id); | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('invoice_id', $this->input['report_keys'])) | ||||
|             $entity['invoice'] = $quote->invoice ? $quote->invoice->number : ""; | ||||
|         if (in_array('invoice_id', $this->input['report_keys'])) { | ||||
|             $entity['invoice'] = $quote->invoice ? $quote->invoice->number : ''; | ||||
|         } | ||||
| 
 | ||||
|         return $entity; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -85,7 +85,6 @@ class QuoteItemExport extends BaseExport | ||||
|         'custom_value4' => 'item.custom_value4', | ||||
|     ]; | ||||
| 
 | ||||
| 
 | ||||
|     private array $decorate_keys = [ | ||||
|         'client', | ||||
|         'currency', | ||||
| @ -100,7 +99,6 @@ class QuoteItemExport extends BaseExport | ||||
| 
 | ||||
|     public function run() | ||||
|     { | ||||
| 
 | ||||
|         MultiDB::setDb($this->company->db); | ||||
|         App::forgetInstance('translator'); | ||||
|         App::setLocale($this->company->locale()); | ||||
| @ -110,28 +108,25 @@ class QuoteItemExport extends BaseExport | ||||
|         //load the CSV document from a string
 | ||||
|         $this->csv = Writer::createFromString(); | ||||
| 
 | ||||
|         if(count($this->input['report_keys']) == 0) | ||||
|         if (count($this->input['report_keys']) == 0) { | ||||
|             $this->input['report_keys'] = array_values($this->entity_keys); | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         //insert the header
 | ||||
|         $this->csv->insertOne($this->buildHeader()); | ||||
| 
 | ||||
|         $query = Quote::query() | ||||
|                         ->with('client')->where('company_id', $this->company->id) | ||||
|                         ->where('is_deleted',0); | ||||
|                         ->where('is_deleted', 0); | ||||
| 
 | ||||
|         $query = $this->addDateRange($query); | ||||
| 
 | ||||
|         $query->cursor() | ||||
|             ->each(function ($quote){ | ||||
| 
 | ||||
|             ->each(function ($quote) { | ||||
|                 $this->iterateItems($quote); | ||||
|             }); | ||||
| 
 | ||||
|         }); | ||||
| 
 | ||||
|         return $this->csv->toString();  | ||||
| 
 | ||||
|         return $this->csv->toString(); | ||||
|     } | ||||
| 
 | ||||
|     private function iterateItems(Quote $quote) | ||||
| @ -140,76 +135,68 @@ class QuoteItemExport extends BaseExport | ||||
| 
 | ||||
|         $transformed_items = []; | ||||
| 
 | ||||
|         foreach($quote->line_items as $item) | ||||
|         { | ||||
|         foreach ($quote->line_items as $item) { | ||||
|             $item_array = []; | ||||
| 
 | ||||
|             foreach(array_values($this->input['report_keys']) as $key){ | ||||
|              | ||||
|                 if(str_contains($key, "item.")){ | ||||
| 
 | ||||
|                     $key = str_replace("item.", "", $key); | ||||
|             foreach (array_values($this->input['report_keys']) as $key) { | ||||
|                 if (str_contains($key, 'item.')) { | ||||
|                     $key = str_replace('item.', '', $key); | ||||
|                     $item_array[$key] = $item->{$key}; | ||||
|                 } | ||||
| 
 | ||||
|             } | ||||
| 
 | ||||
|             $entity = []; | ||||
| 
 | ||||
|             foreach(array_values($this->input['report_keys']) as $key) | ||||
|             { | ||||
|             foreach (array_values($this->input['report_keys']) as $key) { | ||||
|                 $keyval = array_search($key, $this->entity_keys); | ||||
| 
 | ||||
|                 if(array_key_exists($key, $transformed_items)) | ||||
|                 if (array_key_exists($key, $transformed_items)) { | ||||
|                     $entity[$keyval] = $transformed_items[$key]; | ||||
|                 else  | ||||
|                     $entity[$keyval] = ""; | ||||
|                 } else { | ||||
|                     $entity[$keyval] = ''; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
| 
 | ||||
|             $transformed_items = array_merge($transformed_quote, $item_array); | ||||
|             $entity = $this->decorateAdvancedFields($quote, $transformed_items); | ||||
| 
 | ||||
|             $this->csv->insertOne($entity);  | ||||
| 
 | ||||
|             $this->csv->insertOne($entity); | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private function buildRow(Quote $quote) :array | ||||
|     { | ||||
| 
 | ||||
|         $transformed_quote = $this->quote_transformer->transform($quote); | ||||
| 
 | ||||
|         $entity = []; | ||||
| 
 | ||||
|         foreach(array_values($this->input['report_keys']) as $key){ | ||||
| 
 | ||||
|         foreach (array_values($this->input['report_keys']) as $key) { | ||||
|             $keyval = array_search($key, $this->entity_keys); | ||||
| 
 | ||||
|             if(array_key_exists($key, $transformed_quote)) | ||||
|             if (array_key_exists($key, $transformed_quote)) { | ||||
|                 $entity[$keyval] = $transformed_quote[$key]; | ||||
|             else | ||||
|                 $entity[$keyval] = ""; | ||||
| 
 | ||||
|             } else { | ||||
|                 $entity[$keyval] = ''; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return $this->decorateAdvancedFields($quote, $entity); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private function decorateAdvancedFields(Quote $quote, array $entity) :array | ||||
|     { | ||||
|         if(in_array('currency_id', $this->input['report_keys'])) | ||||
|         if (in_array('currency_id', $this->input['report_keys'])) { | ||||
|             $entity['currency'] = $quote->client->currency() ? $quote->client->currency()->code : $quote->company->currency()->code; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('client_id', $this->input['report_keys'])) | ||||
|         if (in_array('client_id', $this->input['report_keys'])) { | ||||
|             $entity['client'] = $quote->client->present()->name(); | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('status_id', $this->input['report_keys'])) | ||||
|         if (in_array('status_id', $this->input['report_keys'])) { | ||||
|             $entity['status'] = $quote->stringStatus($quote->status_id); | ||||
|         } | ||||
| 
 | ||||
|         return $entity; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -74,7 +74,7 @@ class RecurringInvoiceExport extends BaseExport | ||||
|         'currency', | ||||
|         'status', | ||||
|         'vendor', | ||||
|         'project' | ||||
|         'project', | ||||
|     ]; | ||||
| 
 | ||||
|     public function __construct(Company $company, array $input) | ||||
| @ -86,7 +86,6 @@ class RecurringInvoiceExport extends BaseExport | ||||
| 
 | ||||
|     public function run() | ||||
|     { | ||||
| 
 | ||||
|         MultiDB::setDb($this->company->db); | ||||
|         App::forgetInstance('translator'); | ||||
|         App::setLocale($this->company->locale()); | ||||
| @ -96,8 +95,9 @@ class RecurringInvoiceExport extends BaseExport | ||||
|         //load the CSV document from a string
 | ||||
|         $this->csv = Writer::createFromString(); | ||||
| 
 | ||||
|         if(count($this->input['report_keys']) == 0) | ||||
|         if (count($this->input['report_keys']) == 0) { | ||||
|             $this->input['report_keys'] = array_values($this->entity_keys); | ||||
|         } | ||||
| 
 | ||||
|         //insert the header
 | ||||
|         $this->csv->insertOne($this->buildHeader()); | ||||
| @ -105,64 +105,63 @@ class RecurringInvoiceExport extends BaseExport | ||||
|         $query = RecurringInvoice::query() | ||||
|                         ->withTrashed() | ||||
|                         ->with('client')->where('company_id', $this->company->id) | ||||
|                         ->where('is_deleted',0); | ||||
|                         ->where('is_deleted', 0); | ||||
| 
 | ||||
|         $query = $this->addDateRange($query); | ||||
| 
 | ||||
|         $query->cursor() | ||||
|             ->each(function ($invoice){ | ||||
| 
 | ||||
|                 $this->csv->insertOne($this->buildRow($invoice));  | ||||
| 
 | ||||
|         }); | ||||
| 
 | ||||
|         return $this->csv->toString();  | ||||
|             ->each(function ($invoice) { | ||||
|                 $this->csv->insertOne($this->buildRow($invoice)); | ||||
|             }); | ||||
| 
 | ||||
|         return $this->csv->toString(); | ||||
|     } | ||||
| 
 | ||||
|     private function buildRow(RecurringInvoice $invoice) :array | ||||
|     { | ||||
| 
 | ||||
|         $transformed_invoice = $this->invoice_transformer->transform($invoice); | ||||
| 
 | ||||
|         $entity = []; | ||||
| 
 | ||||
|         foreach(array_values($this->input['report_keys']) as $key){ | ||||
| 
 | ||||
|         foreach (array_values($this->input['report_keys']) as $key) { | ||||
|             $keyval = array_search($key, $this->entity_keys); | ||||
| 
 | ||||
|             if(array_key_exists($key, $transformed_invoice)) | ||||
|             if (array_key_exists($key, $transformed_invoice)) { | ||||
|                 $entity[$keyval] = $transformed_invoice[$key]; | ||||
|             else | ||||
|             } else { | ||||
|                 $entity[$keyval] = ''; | ||||
| 
 | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return $this->decorateAdvancedFields($invoice, $entity); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private function decorateAdvancedFields(RecurringInvoice $invoice, array $entity) :array | ||||
|     { | ||||
|         if(in_array('country_id', $this->input['report_keys'])) | ||||
|             $entity['country'] = $invoice->client->country ? ctrans("texts.country_{$invoice->client->country->name}") : "";  | ||||
|         if (in_array('country_id', $this->input['report_keys'])) { | ||||
|             $entity['country'] = $invoice->client->country ? ctrans("texts.country_{$invoice->client->country->name}") : ''; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('currency_id', $this->input['report_keys'])) | ||||
|         if (in_array('currency_id', $this->input['report_keys'])) { | ||||
|             $entity['currency'] = $invoice->client->currency() ? $invoice->client->currency()->code : $invoice->company->currency()->code; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('client_id', $this->input['report_keys'])) | ||||
|         if (in_array('client_id', $this->input['report_keys'])) { | ||||
|             $entity['client'] = $invoice->client->present()->name(); | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('status_id',$this->input['report_keys'])) | ||||
|         if (in_array('status_id', $this->input['report_keys'])) { | ||||
|             $entity['status'] = $invoice->stringStatus($invoice->status_id); | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('project_id',$this->input['report_keys'])) | ||||
|             $entity['project'] = $invoice->project ? $invoice->project->name : ""; | ||||
|         if (in_array('project_id', $this->input['report_keys'])) { | ||||
|             $entity['project'] = $invoice->project ? $invoice->project->name : ''; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('vendor_id',$this->input['report_keys'])) | ||||
|             $entity['vendor'] = $invoice->vendor ? $invoice->vendor->name : ""; | ||||
|         if (in_array('vendor_id', $this->input['report_keys'])) { | ||||
|             $entity['vendor'] = $invoice->vendor ? $invoice->vendor->name : ''; | ||||
|         } | ||||
| 
 | ||||
|         return $entity; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -71,7 +71,6 @@ class TaskExport extends BaseExport | ||||
| 
 | ||||
|     public function run() | ||||
|     { | ||||
| 
 | ||||
|         MultiDB::setDb($this->company->db); | ||||
|         App::forgetInstance('translator'); | ||||
|         App::setLocale($this->company->locale()); | ||||
| @ -79,15 +78,15 @@ class TaskExport extends BaseExport | ||||
|         $t->replace(Ninja::transformTranslations($this->company->settings)); | ||||
| 
 | ||||
|         $this->date_format = DateFormat::find($this->company->settings->date_format_id)->format; | ||||
|      | ||||
| 
 | ||||
|         //load the CSV document from a string
 | ||||
|         $this->csv = Writer::createFromString(); | ||||
|          | ||||
| 
 | ||||
|         ksort($this->entity_keys); | ||||
| 
 | ||||
|         if(count($this->input['report_keys']) == 0) | ||||
|         if (count($this->input['report_keys']) == 0) { | ||||
|             $this->input['report_keys'] = array_values($this->entity_keys); | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         //insert the header
 | ||||
|         $this->csv->insertOne($this->buildHeader()); | ||||
| @ -97,59 +96,50 @@ class TaskExport extends BaseExport | ||||
|         $query = $this->addDateRange($query); | ||||
| 
 | ||||
|         $query->cursor() | ||||
|               ->each(function ($entity){ | ||||
| 
 | ||||
|                 $this->buildRow($entity);  | ||||
| 
 | ||||
|         }); | ||||
| 
 | ||||
|         return $this->csv->toString();  | ||||
|               ->each(function ($entity) { | ||||
|                   $this->buildRow($entity); | ||||
|               }); | ||||
| 
 | ||||
|         return $this->csv->toString(); | ||||
|     } | ||||
| 
 | ||||
|     private function buildRow(Task $task)  | ||||
|     private function buildRow(Task $task) | ||||
|     { | ||||
| 
 | ||||
|         $entity = []; | ||||
|         $transformed_entity = $this->entity_transformer->transform($task); | ||||
| 
 | ||||
|         if(is_null($task->time_log) || (is_array(json_decode($task->time_log,1)) && count(json_decode($task->time_log,1)) == 0)){ | ||||
| 
 | ||||
|             foreach(array_values($this->input['report_keys']) as $key){ | ||||
| 
 | ||||
|         if (is_null($task->time_log) || (is_array(json_decode($task->time_log, 1)) && count(json_decode($task->time_log, 1)) == 0)) { | ||||
|             foreach (array_values($this->input['report_keys']) as $key) { | ||||
|                 $keyval = array_search($key, $this->entity_keys); | ||||
| 
 | ||||
|                 if(array_key_exists($key, $transformed_entity)) | ||||
|                 if (array_key_exists($key, $transformed_entity)) { | ||||
|                     $entity[$keyval] = $transformed_entity[$key]; | ||||
|                 else | ||||
|                     $entity[$keyval] = '';             | ||||
|                 } else { | ||||
|                     $entity[$keyval] = ''; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             $entity['start_date'] = ""; | ||||
|             $entity['end_date'] = ""; | ||||
|             $entity['duration'] = ""; | ||||
|             $entity['start_date'] = ''; | ||||
|             $entity['end_date'] = ''; | ||||
|             $entity['duration'] = ''; | ||||
| 
 | ||||
|             $entity = $this->decorateAdvancedFields($task, $entity); | ||||
| 
 | ||||
|             ksort($entity); | ||||
|             $this->csv->insertOne($entity); | ||||
| 
 | ||||
|         } | ||||
|         elseif(is_array(json_decode($task->time_log,1)) && count(json_decode($task->time_log,1)) > 0) { | ||||
| 
 | ||||
|             foreach(array_values($this->input['report_keys']) as $key){ | ||||
| 
 | ||||
|         } elseif (is_array(json_decode($task->time_log, 1)) && count(json_decode($task->time_log, 1)) > 0) { | ||||
|             foreach (array_values($this->input['report_keys']) as $key) { | ||||
|                 $keyval = array_search($key, $this->entity_keys); | ||||
| 
 | ||||
|                 if(array_key_exists($key, $transformed_entity)) | ||||
|                 if (array_key_exists($key, $transformed_entity)) { | ||||
|                     $entity[$keyval] = $transformed_entity[$key]; | ||||
|                 else | ||||
|                     $entity[$keyval] = '';             | ||||
|                 } else { | ||||
|                     $entity[$keyval] = ''; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             $this->iterateLogs($task, $entity); | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private function iterateLogs(Task $task, array $entity) | ||||
| @ -157,48 +147,51 @@ class TaskExport extends BaseExport | ||||
|         $timezone = Timezone::find($task->company->settings->timezone_id); | ||||
|         $timezone_name = 'US/Eastern'; | ||||
| 
 | ||||
|         if($timezone) | ||||
|         if ($timezone) { | ||||
|             $timezone_name = $timezone->name; | ||||
|         } | ||||
| 
 | ||||
|         $logs = json_decode($task->time_log,1); | ||||
|          | ||||
|         $date_format_default = "Y-m-d"; | ||||
|         $logs = json_decode($task->time_log, 1); | ||||
| 
 | ||||
|         $date_format_default = 'Y-m-d'; | ||||
| 
 | ||||
|         $date_format = DateFormat::find($task->company->settings->date_format_id); | ||||
| 
 | ||||
|         if($date_format) | ||||
|         if ($date_format) { | ||||
|             $date_format_default = $date_format->format; | ||||
|         } | ||||
| 
 | ||||
|         foreach($logs as $key => $item) | ||||
|         { | ||||
| 
 | ||||
|             if(in_array("start_date", $this->input['report_keys'])){ | ||||
|         foreach ($logs as $key => $item) { | ||||
|             if (in_array('start_date', $this->input['report_keys'])) { | ||||
|                 $entity['start_date'] = Carbon::createFromTimeStamp($item[0])->setTimezone($timezone_name)->format($date_format_default); | ||||
|             } | ||||
| 
 | ||||
|             if(in_array("end_date", $this->input['report_keys']) && $item[1] > 0){ | ||||
|             if (in_array('end_date', $this->input['report_keys']) && $item[1] > 0) { | ||||
|                 $entity['end_date'] = Carbon::createFromTimeStamp($item[1])->setTimezone($timezone_name)->format($date_format_default); | ||||
|             } | ||||
| 
 | ||||
|             if(in_array("end_date", $this->input['report_keys']) && $item[1] == 0){ | ||||
|             if (in_array('end_date', $this->input['report_keys']) && $item[1] == 0) { | ||||
|                 $entity['end_date'] = ctrans('texts.is_running'); | ||||
|             } | ||||
| 
 | ||||
|             if(in_array("duration", $this->input['report_keys'])){ | ||||
|             if (in_array('duration', $this->input['report_keys'])) { | ||||
|                 $entity['duration'] = $task->calcDuration(); | ||||
|             } | ||||
| 
 | ||||
|             if(!array_key_exists('duration', $entity)) | ||||
|                 $entity['duration'] = ""; | ||||
|             if (! array_key_exists('duration', $entity)) { | ||||
|                 $entity['duration'] = ''; | ||||
|             } | ||||
| 
 | ||||
|             if(!array_key_exists('start_date', $entity)) | ||||
|                 $entity['start_date'] = ""; | ||||
|             if (! array_key_exists('start_date', $entity)) { | ||||
|                 $entity['start_date'] = ''; | ||||
|             } | ||||
| 
 | ||||
|             if(!array_key_exists('end_date', $entity)) | ||||
|                 $entity['end_date'] = ""; | ||||
|             if (! array_key_exists('end_date', $entity)) { | ||||
|                 $entity['end_date'] = ''; | ||||
|             } | ||||
| 
 | ||||
|             $entity = $this->decorateAdvancedFields($task, $entity); | ||||
|              | ||||
| 
 | ||||
|             ksort($entity); | ||||
|             $this->csv->insertOne($entity); | ||||
| 
 | ||||
| @ -206,25 +199,26 @@ class TaskExport extends BaseExport | ||||
|             unset($entity['end_date']); | ||||
|             unset($entity['duration']); | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private function decorateAdvancedFields(Task $task, array $entity) :array | ||||
|     { | ||||
| 
 | ||||
|         if(in_array('status_id', $this->input['report_keys'])) | ||||
|         if (in_array('status_id', $this->input['report_keys'])) { | ||||
|             $entity['status'] = $task->status()->exists() ? $task->status->name : ''; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('project_id', $this->input['report_keys'])) | ||||
|         if (in_array('project_id', $this->input['report_keys'])) { | ||||
|             $entity['project'] = $task->project()->exists() ? $task->project->name : ''; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('client_id', $this->input['report_keys'])) | ||||
|             $entity['client'] = $task->client ? $task->client->present()->name() : ""; | ||||
|         if (in_array('client_id', $this->input['report_keys'])) { | ||||
|             $entity['client'] = $task->client ? $task->client->present()->name() : ''; | ||||
|         } | ||||
| 
 | ||||
|         if(in_array('invoice_id', $this->input['report_keys'])) | ||||
|             $entity['invoice'] = $task->invoice ? $task->invoice->number : ""; | ||||
|         if (in_array('invoice_id', $this->input['report_keys'])) { | ||||
|             $entity['invoice'] = $task->invoice ? $task->invoice->number : ''; | ||||
|         } | ||||
| 
 | ||||
|         return $entity; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -25,7 +25,7 @@ class ClientGatewayTokenFactory | ||||
|         $client_gateway_token->is_deleted = false; | ||||
|         $client_gateway_token->token = ''; | ||||
|         $client_gateway_token->routing_number = ''; | ||||
|          | ||||
| 
 | ||||
|         return $client_gateway_token; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -28,11 +28,12 @@ class CloneQuoteToInvoiceFactory | ||||
|         unset($quote_array['invoice_id']); | ||||
|         unset($quote_array['id']); | ||||
|         unset($quote_array['invitations']); | ||||
|          | ||||
| 
 | ||||
|         //preserve terms if they exist on Quotes
 | ||||
|         //if(array_key_exists('terms', $quote_array) && strlen($quote_array['terms']) < 2)
 | ||||
|         if(!$quote->company->use_quote_terms_on_conversion) | ||||
|         if (! $quote->company->use_quote_terms_on_conversion) { | ||||
|             unset($quote_array['terms']); | ||||
|         } | ||||
| 
 | ||||
|         // unset($quote_array['public_notes']);
 | ||||
|         unset($quote_array['footer']); | ||||
|  | ||||
| @ -37,12 +37,13 @@ class CompanyFactory | ||||
|         //$company->custom_fields = (object) ['invoice1' => '1', 'invoice2' => '2', 'client1'=>'3'];
 | ||||
|         $company->custom_fields = (object) []; | ||||
|         $company->client_registration_fields = ClientRegistrationFields::generate(); | ||||
|          | ||||
|         if(Ninja::isHosted()) | ||||
| 
 | ||||
|         if (Ninja::isHosted()) { | ||||
|             $company->subdomain = MultiDB::randomSubdomainGenerator(); | ||||
|         else  | ||||
|         } else { | ||||
|             $company->subdomain = ''; | ||||
|          | ||||
|         } | ||||
| 
 | ||||
|         $company->enabled_modules = config('ninja.enabled_modules'); //32767;//8191; //4095
 | ||||
|         $company->default_password_timeout = 1800000; | ||||
|         $company->markdown_email_enabled = false; | ||||
|  | ||||
| @ -24,7 +24,7 @@ class CompanyGatewayFactory | ||||
|         $company_gateway->require_billing_address = false; | ||||
|         $company_gateway->require_shipping_address = false; | ||||
|         $company_gateway->config = encrypt(json_encode(new \stdClass)); | ||||
|          | ||||
| 
 | ||||
|         return $company_gateway; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -23,7 +23,7 @@ class ExpenseCategoryFactory | ||||
|         $expense->name = ''; | ||||
|         $expense->is_deleted = false; | ||||
|         $expense->color = ''; | ||||
|          | ||||
| 
 | ||||
|         return $expense; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -42,7 +42,7 @@ class ExpenseFactory | ||||
|         $expense->tax_amount1 = 0; | ||||
|         $expense->tax_amount2 = 0; | ||||
|         $expense->tax_amount3 = 0; | ||||
|          | ||||
| 
 | ||||
|         return $expense; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -18,8 +18,8 @@ class GroupSettingFactory | ||||
| { | ||||
|     public static function create(int $company_id, int $user_id) :GroupSetting | ||||
|     { | ||||
|     	$settings = new \stdClass; | ||||
|     	$settings->entity = Client::class; | ||||
|         $settings = new \stdClass; | ||||
|         $settings->entity = Client::class; | ||||
| 
 | ||||
|         $gs = new GroupSetting; | ||||
|         $gs->name = ''; | ||||
|  | ||||
| @ -40,7 +40,7 @@ class InvoiceItemFactory | ||||
|         $item->custom_value2 = ''; | ||||
|         $item->custom_value3 = ''; | ||||
|         $item->custom_value4 = ''; | ||||
|         $item->type_id = "1"; | ||||
|         $item->type_id = '1'; | ||||
| 
 | ||||
|         return $item; | ||||
|     } | ||||
| @ -71,7 +71,7 @@ class InvoiceItemFactory | ||||
|             // $item->custom_value4 = $faker->realText(10);
 | ||||
|             $item->tax_name1 = 'GST'; | ||||
|             $item->tax_rate1 = 10.00; | ||||
|             $item->type_id = "1"; | ||||
|             $item->type_id = '1'; | ||||
| 
 | ||||
|             $data[] = $item; | ||||
|         } | ||||
| @ -105,7 +105,7 @@ class InvoiceItemFactory | ||||
|             // $item->custom_value4 = $faker->realText(10);
 | ||||
|             $item->tax_name1 = ''; | ||||
|             $item->tax_rate1 = 0; | ||||
|             $item->type_id = "1"; | ||||
|             $item->type_id = '1'; | ||||
| 
 | ||||
|             $data[] = $item; | ||||
|         } | ||||
|  | ||||
| @ -31,7 +31,7 @@ class ProjectFactory | ||||
|         $project->custom_value3 = ''; | ||||
|         $project->custom_value4 = ''; | ||||
|         $project->is_deleted = 0; | ||||
|          | ||||
| 
 | ||||
|         return $project; | ||||
|     } | ||||
| } | ||||
|  | ||||
Some files were not shown because too many files have changed in this diff Show More
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user