mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-03 22:47:32 -05:00 
			
		
		
		
	Move null filter to basemodel
This commit is contained in:
		
							parent
							
								
									94da1d9ded
								
							
						
					
					
						commit
						516533c374
					
				@ -304,6 +304,31 @@ class BaseModel extends Model
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
    /**
 | 
			
		||||
     * arrayFilterRecursive
 | 
			
		||||
     *
 | 
			
		||||
     * Removes null properties from an array
 | 
			
		||||
     * 
 | 
			
		||||
     * @param  array $array
 | 
			
		||||
     * @return array
 | 
			
		||||
     */
 | 
			
		||||
    public function arrayFilterRecursive(array $array): array
 | 
			
		||||
    {
 | 
			
		||||
        foreach ($array as $key => $value) {
 | 
			
		||||
            if (is_array($value)) {
 | 
			
		||||
                // Recursively filter the nested array
 | 
			
		||||
                $array[$key] = $this->arrayFilterRecursive($value);
 | 
			
		||||
            }
 | 
			
		||||
            // Remove null values
 | 
			
		||||
            if (is_null($array[$key])) {
 | 
			
		||||
                unset($array[$key]);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $array;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the base64 encoded PDF string of the entity
 | 
			
		||||
     * @deprecated - unused implementation
 | 
			
		||||
 | 
			
		||||
@ -50,7 +50,7 @@ use Laracasts\Presenter\PresentableTrait;
 | 
			
		||||
 * @property int|null $last_login
 | 
			
		||||
 * @property int|null $industry_id
 | 
			
		||||
 * @property int|null $size_id
 | 
			
		||||
 * @property object|null $e_invoice
 | 
			
		||||
 * @property object|array|null $e_invoice
 | 
			
		||||
 * @property string|null $address1
 | 
			
		||||
 * @property string|null $address2
 | 
			
		||||
 * @property string|null $city
 | 
			
		||||
 | 
			
		||||
@ -76,6 +76,13 @@ class ClientRepository extends BaseRepository
 | 
			
		||||
            $client->country_id = $company->settings->country_id;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if(isset($data['e_invoice']) && is_array($data['e_invoice'])) {
 | 
			
		||||
            //ensure it is normalized first!
 | 
			
		||||
            $data['e_invoice'] = $client->arrayFilterRecursive($data['e_invoice']);
 | 
			
		||||
 | 
			
		||||
            $client->e_invoice = $data['e_invoice'];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $client->save();
 | 
			
		||||
 | 
			
		||||
        if (! isset($client->number) || empty($client->number) || strlen($client->number) == 0) {
 | 
			
		||||
@ -107,6 +114,7 @@ class ClientRepository extends BaseRepository
 | 
			
		||||
            $this->contact_repo->save($contact_data, $client);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        return $client;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -60,7 +60,7 @@ class CompanyRepository extends BaseRepository
 | 
			
		||||
 | 
			
		||||
        if(isset($data['e_invoice']) && is_array($data['e_invoice'])){
 | 
			
		||||
            //ensure it is normalized first!
 | 
			
		||||
            $data['e_invoice'] = $this->arrayFilterRecursive($data['e_invoice']);
 | 
			
		||||
            $data['e_invoice'] = $company->arrayFilterRecursive($data['e_invoice']);
 | 
			
		||||
 | 
			
		||||
            $company->e_invoice = $data['e_invoice'];
 | 
			
		||||
        }
 | 
			
		||||
@ -70,24 +70,6 @@ class CompanyRepository extends BaseRepository
 | 
			
		||||
        return $company;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
    private function arrayFilterRecursive(array $array): array
 | 
			
		||||
    {
 | 
			
		||||
        foreach ($array as $key => $value) {
 | 
			
		||||
            if (is_array($value)) {
 | 
			
		||||
                // Recursively filter the nested array
 | 
			
		||||
                $array[$key] = $this->arrayFilterRecursive($value);
 | 
			
		||||
            }
 | 
			
		||||
            // Remove null values
 | 
			
		||||
            if (is_null($array[$key])) {
 | 
			
		||||
                unset($array[$key]);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $array;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * parseCustomFields
 | 
			
		||||
     *
 | 
			
		||||
 | 
			
		||||
@ -123,10 +123,11 @@ class SendEDocument implements ShouldQueue
 | 
			
		||||
        $activity->company_id = $model->company_id;
 | 
			
		||||
        $activity->activity_type_id = Activity::EMAIL_EINVOICE_SUCCESS;
 | 
			
		||||
        $activity->invoice_id = $model->id;
 | 
			
		||||
        $activity->notes = $guid;
 | 
			
		||||
        $activity->notes = str_replace('"', '', $guid);
 | 
			
		||||
 | 
			
		||||
        $activity->save();
 | 
			
		||||
 | 
			
		||||
        $model->backup = $guid;
 | 
			
		||||
        $model->backup = str_replace('"', '', $guid);
 | 
			
		||||
        $model->saveQuietly();
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -276,7 +276,7 @@ class Peppol extends AbstractService
 | 
			
		||||
            $this->p_invoice->DueDate = new \DateTime($this->invoice->due_date);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $this->p_invoice->InvoiceTypeCode = 380; //
 | 
			
		||||
        $this->p_invoice->InvoiceTypeCode = ($this->invoice->amount >= 0) ? 380 : 381; //
 | 
			
		||||
        $this->p_invoice->AccountingSupplierParty = $this->getAccountingSupplierParty();
 | 
			
		||||
        $this->p_invoice->AccountingCustomerParty = $this->getAccountingCustomerParty();
 | 
			
		||||
        $this->p_invoice->InvoiceLine = $this->getInvoiceLines();
 | 
			
		||||
 | 
			
		||||
@ -201,8 +201,8 @@
 | 
			
		||||
            "url": "https://github.com/turbo124/snappdf"
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
            "type":"vcs",
 | 
			
		||||
            "url":"https://github.com/karneaud/QuickBooks-V3-PHP-SDK.git"
 | 
			
		||||
            "type": "vcs",
 | 
			
		||||
            "url": "https://github.com/karneaud/QuickBooks-V3-PHP-SDK.git"
 | 
			
		||||
        }
 | 
			
		||||
    ],
 | 
			
		||||
    "minimum-stability": "dev",
 | 
			
		||||
 | 
			
		||||
@ -67,7 +67,7 @@ use InvoiceNinja\EInvoice\Models\Peppol\TaxCategoryType\TaxCategory;
 | 
			
		||||
/**
 | 
			
		||||
 * @test
 | 
			
		||||
 */
 | 
			
		||||
class FACT1Test extends TestCase
 | 
			
		||||
class Fact1Test extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    use MockAccountData;
 | 
			
		||||
    use DatabaseTransactions;
 | 
			
		||||
 | 
			
		||||
@ -9,6 +9,8 @@
 | 
			
		||||
 * @license https://www.elastic.co/licensing/elastic-license
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace Tests\Unit;
 | 
			
		||||
 | 
			
		||||
use App\Jobs\EDocument\CreateEDocument;
 | 
			
		||||
use App\Jobs\Entity\CreateRawPdf;
 | 
			
		||||
use horstoeko\zugferd\ZugferdDocumentReader;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user