mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-31 03:37:31 -04:00 
			
		
		
		
	add logic for import payment entity
This commit is contained in:
		
							parent
							
								
									3e0c6f2986
								
							
						
					
					
						commit
						43b95125f0
					
				| @ -15,16 +15,20 @@ use App\Models\Invoice; | ||||
| use App\Factory\ProductFactory; | ||||
| use App\Factory\ClientFactory; | ||||
| use App\Factory\InvoiceFactory; | ||||
| use App\Factory\PaymentFactory; | ||||
| use Illuminate\Support\Facades\Cache; | ||||
| use App\Http\Requests\Client\StoreClientRequest; | ||||
| use App\Http\Requests\Product\StoreProductRequest; | ||||
| use App\Http\Requests\Invoice\StoreInvoiceRequest; | ||||
| use App\Import\Transformer\Quickbooks\ClientTransformer; | ||||
| use App\Import\Transformer\Quickbooks\InvoiceTransformer; | ||||
| use App\Import\Transformer\Quickbooks\ProductTransformer; | ||||
| use App\Repositories\ClientRepository; | ||||
| use App\Repositories\InvoiceRepository; | ||||
| use App\Repositories\ProductRepository; | ||||
| use App\Repositories\PaymentRepository; | ||||
| use App\Http\Requests\Client\StoreClientRequest; | ||||
| use App\Http\Requests\Product\StoreProductRequest; | ||||
| use App\Http\Requests\Invoice\StoreInvoiceRequest; | ||||
| use App\Http\Requests\Payment\StorePaymentRequest; | ||||
| use App\Import\Transformer\Quickbooks\ClientTransformer; | ||||
| use App\Import\Transformer\Quickbooks\InvoiceTransformer; | ||||
| use App\Import\Transformer\Quickbooks\ProductTransformer; | ||||
| use App\Import\Transformer\Quickbooks\PaymentTransformer; | ||||
| 
 | ||||
| class Quickbooks extends BaseImport | ||||
| { | ||||
| @ -98,7 +102,22 @@ class Quickbooks extends BaseImport | ||||
| 
 | ||||
|     public function payment() | ||||
|     { | ||||
|         $entity_type = 'payment'; | ||||
|         $data = $this->getData($entity_type); | ||||
|         if (empty($data)) { | ||||
|             $this->entity_count['payments'] = 0; | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         $this->request_name = StorePaymentRequest::class; | ||||
|         $this->repository_name = PaymentRepository::class; | ||||
|         $this->factory_name = PaymentFactory::class; | ||||
|         $this->repository = app()->make($this->repository_name); | ||||
|         $this->repository->import_mode = true; | ||||
|         $this->transformer = new PaymentTransformer($this->company); | ||||
|         $count = $this->ingest($data, $entity_type); | ||||
|         $this->entity_count['payments'] = $count; | ||||
|     } | ||||
| 
 | ||||
|     public function invoice() | ||||
|  | ||||
							
								
								
									
										100
									
								
								app/Import/Transformer/Quickbooks/PaymentTransformer.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										100
									
								
								app/Import/Transformer/Quickbooks/PaymentTransformer.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,100 @@ | ||||
| <?php | ||||
| 
 | ||||
| /** | ||||
|  * Invoice Ninja (https://Paymentninja.com). | ||||
|  * | ||||
|  * @link https://github.com/invoiceninja/invoiceninja source repository | ||||
|  * | ||||
|  * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com) | ||||
|  * | ||||
|  * @license https://www.elastic.co/licensing/elastic-license | ||||
|  */ | ||||
| 
 | ||||
| namespace App\Import\Transformer\Quickbooks; | ||||
| 
 | ||||
| use App\Import\Transformer\Quickbooks\CommonTrait; | ||||
| use App\Import\Transformer\BaseTransformer; | ||||
| use App\Models\Payment as Model; | ||||
| use App\Import\ImportException; | ||||
| use Illuminate\Support\Str; | ||||
| use Illuminate\Support\Arr; | ||||
| use App\Models\Invoice; | ||||
| 
 | ||||
| /** | ||||
|  *  | ||||
|  * Class PaymentTransformer. | ||||
|  */ | ||||
| class PaymentTransformer extends BaseTransformer | ||||
| { | ||||
|     use CommonTrait; | ||||
| 
 | ||||
|     protected $fillable = [ | ||||
|         'number' => "PaymentRefNum", | ||||
|         'amount' => "TotalAmt", | ||||
|         "client_id" => "CustomerRef", | ||||
|         "currency_id" => "CurrencyRef", | ||||
|         'date' => "TxnDate", | ||||
|         "invoices" => "Line", | ||||
|         'private_notes' => "PrivateNote", | ||||
|         'created_at' => "CreateTime", | ||||
|         'updated_at' => "LastUpdatedTime" | ||||
|     ]; | ||||
| 
 | ||||
|     public function __construct($company) | ||||
|     { | ||||
|         parent::__construct($company); | ||||
| 
 | ||||
|         $this->model = new Model; | ||||
|     } | ||||
| 
 | ||||
|     public function getTotalAmt($data, $field = null) { | ||||
|         return (float) $this->getString($data, $field); | ||||
|     } | ||||
| 
 | ||||
|     public function getTxnDate($data, $field = null) | ||||
|     { | ||||
|         return $this->parseDateOrNull($data, $field); | ||||
|     } | ||||
| 
 | ||||
|     public function getCustomerRef($data, $field = null ) | ||||
|     { | ||||
|         return $this->getClient($this->getString($data, 'CustomerRef.name'),null); | ||||
|     } | ||||
| 
 | ||||
|     public function getCurrencyRef($data, $field = null)  | ||||
|     { | ||||
|         return $this->getCurrencyByCode($data['CurrencyRef'], 'value'); | ||||
|     } | ||||
| 
 | ||||
|     public function getLine($data, $field = null) | ||||
|     { | ||||
|         $invoices = []; | ||||
|         $invoice = $this->getString($data,'Line.LinkedTxn.TxnType'); | ||||
|         nlog(print_r([$invoice, $this->getString($data,'Line.LinkedTxn')], true)); | ||||
|         if(is_null($invoice) || $invoice !== 'Invoice') return $invoices; | ||||
|         if( is_null( ($invoice_id = $this->getInvoiceId($this->getString($data, 'Line.LinkedTxn.TxnId.value')))) ) return $invoices; | ||||
|          | ||||
|         return [[ | ||||
|             'amount' => (float) $this->getString($data, 'Line.Amount'), | ||||
|             'invoice_id' => $invoice_id | ||||
|         ]]; | ||||
|     } | ||||
| 
 | ||||
|      /** | ||||
|      * @param $invoice_number | ||||
|      * | ||||
|      * @return int|null | ||||
|      */ | ||||
|     public function getInvoiceId($invoice_number) | ||||
|     { | ||||
|         $invoice = Invoice::query()->where('company_id', $this->company->id) | ||||
|             ->where('is_deleted', false) | ||||
|             ->where("number", "LIKE",  | ||||
|                 "%-$invoice_number%", | ||||
|             ) | ||||
|             ->first(); | ||||
| 
 | ||||
|         return $invoice ? $invoice->id : null; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										10
									
								
								app/Repositories/Import/Quickbooks/PaymentRepository.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								app/Repositories/Import/Quickbooks/PaymentRepository.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,10 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace App\Repositories\Import\Quickbooks; | ||||
| 
 | ||||
| use App\Repositories\Import\Quickbooks\Contracts\RepositoryInterface as QuickbooksInterface; | ||||
| 
 | ||||
| class PaymentRepository extends Repository implements QuickbooksInterface | ||||
| { | ||||
|     protected string $entity = "Payment"; | ||||
| } | ||||
| @ -40,6 +40,15 @@ final class Service | ||||
|         return $this->fetchRecords('Invoice', $max) ; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * fetch QuickBooks payment records | ||||
|      * @param int $max The maximum records to fetch. Default 100 | ||||
|      * @return Illuminate\Support\Collection; | ||||
|      */ | ||||
|     public function fetchPayments(int $max = 100): Collection | ||||
|     { | ||||
|         return $this->fetchRecords('Payment', $max) ; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * fetch QuickBooks product records | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user