mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-31 09:27:33 -04:00 
			
		
		
		
	Company Import|Export for purchase orders
This commit is contained in:
		
							parent
							
								
									76b307d20f
								
							
						
					
					
						commit
						5246846018
					
				| @ -400,6 +400,7 @@ class CreateSingleAccount extends Command | |||||||
|         $vendor = Project::factory()->create([ |         $vendor = Project::factory()->create([ | ||||||
|                 'user_id' => $client->user->id, |                 'user_id' => $client->user->id, | ||||||
|                 'company_id' => $client->company->id, |                 'company_id' => $client->company->id, | ||||||
|  |                 'client_id' => $client->id, | ||||||
|             ]); |             ]); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -20,6 +20,7 @@ use App\Mail\DownloadInvoices; | |||||||
| use App\Models\Company; | use App\Models\Company; | ||||||
| use App\Models\CreditInvitation; | use App\Models\CreditInvitation; | ||||||
| use App\Models\InvoiceInvitation; | use App\Models\InvoiceInvitation; | ||||||
|  | use App\Models\PurchaseOrderInvitation; | ||||||
| use App\Models\QuoteInvitation; | use App\Models\QuoteInvitation; | ||||||
| use App\Models\RecurringInvoice; | use App\Models\RecurringInvoice; | ||||||
| use App\Models\RecurringInvoiceInvitation; | use App\Models\RecurringInvoiceInvitation; | ||||||
| @ -32,8 +33,8 @@ use Illuminate\Contracts\Queue\ShouldQueue; | |||||||
| use Illuminate\Foundation\Bus\Dispatchable; | use Illuminate\Foundation\Bus\Dispatchable; | ||||||
| use Illuminate\Queue\InteractsWithQueue; | use Illuminate\Queue\InteractsWithQueue; | ||||||
| use Illuminate\Queue\SerializesModels; | use Illuminate\Queue\SerializesModels; | ||||||
| use Illuminate\Support\Facades\Storage; |  | ||||||
| use Illuminate\Support\Facades\App; | use Illuminate\Support\Facades\App; | ||||||
|  | use Illuminate\Support\Facades\Storage; | ||||||
| 
 | 
 | ||||||
| class CompanyExport implements ShouldQueue | class CompanyExport implements ShouldQueue | ||||||
| { | { | ||||||
| @ -424,9 +425,9 @@ class CompanyExport implements ShouldQueue | |||||||
|         $this->export_data['vendor_contacts'] = VendorContact::where('company_id', $this->company->id)->withTrashed()->cursor()->map(function ($vendor){ |         $this->export_data['vendor_contacts'] = VendorContact::where('company_id', $this->company->id)->withTrashed()->cursor()->map(function ($vendor){ | ||||||
| 
 | 
 | ||||||
|             $vendor = $this->transformBasicEntities($vendor); |             $vendor = $this->transformBasicEntities($vendor); | ||||||
|             $vendor->vendor_id = $this->encodePrimaryKey($vendor->vendor_id); |             $vendor = $this->transformArrayOfKeys($vendor, ['vendor_id']); | ||||||
| 
 | 
 | ||||||
|             return $vendor->makeVisible(['id']); |             return $vendor->makeVisible(['id','user_id']); | ||||||
| 
 | 
 | ||||||
|         })->all(); |         })->all(); | ||||||
| 
 | 
 | ||||||
| @ -439,6 +440,31 @@ class CompanyExport implements ShouldQueue | |||||||
| 
 | 
 | ||||||
|         })->makeHidden(['id'])->all(); |         })->makeHidden(['id'])->all(); | ||||||
| 
 | 
 | ||||||
|  |         $this->export_data['purchase_orders'] = $this->company->purchase_orders()->orderBy('number', 'DESC')->cursor()->map(function ($purchase_order){ | ||||||
|  | 
 | ||||||
|  |             $purchase_order = $this->transformBasicEntities($purchase_order); | ||||||
|  |             $purchase_order = $this->transformArrayOfKeys($purchase_order, ['expense_id','client_id', 'vendor_id', 'project_id', 'design_id', 'subscription_id','project_id']); | ||||||
|  | 
 | ||||||
|  |             return $purchase_order->makeVisible(['id', | ||||||
|  |                                         'private_notes', | ||||||
|  |                                         'user_id', | ||||||
|  |                                         'client_id', | ||||||
|  |                                         'vendor_id', | ||||||
|  |                                         'company_id',]); | ||||||
|  | 
 | ||||||
|  |         })->all(); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |         $this->export_data['purchase_order_invitations'] = PurchaseOrderInvitation::where('company_id', $this->company->id)->withTrashed()->cursor()->map(function ($purchase_order){ | ||||||
|  | 
 | ||||||
|  |             $purchase_order = $this->transformArrayOfKeys($purchase_order, ['company_id', 'user_id', 'vendor_contact_id', 'purchase_order_id']); | ||||||
|  | 
 | ||||||
|  |             return $purchase_order->makeVisible(['id']); | ||||||
|  | 
 | ||||||
|  |         })->all(); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|         //write to tmp and email to owner();
 |         //write to tmp and email to owner();
 | ||||||
|          |          | ||||||
|         $this->zipAndSend();   |         $this->zipAndSend();   | ||||||
|  | |||||||
| @ -45,6 +45,8 @@ use App\Models\PaymentTerm; | |||||||
| use App\Models\Paymentable; | use App\Models\Paymentable; | ||||||
| use App\Models\Product; | use App\Models\Product; | ||||||
| use App\Models\Project; | use App\Models\Project; | ||||||
|  | use App\Models\PurchaseOrder; | ||||||
|  | use App\Models\PurchaseOrderInvitation; | ||||||
| use App\Models\Quote; | use App\Models\Quote; | ||||||
| use App\Models\QuoteInvitation; | use App\Models\QuoteInvitation; | ||||||
| use App\Models\RecurringExpense; | use App\Models\RecurringExpense; | ||||||
| @ -74,7 +76,6 @@ use Illuminate\Support\Str; | |||||||
| use JsonMachine\JsonDecoder\ExtJsonDecoder; | use JsonMachine\JsonDecoder\ExtJsonDecoder; | ||||||
| use JsonMachine\JsonMachine; | use JsonMachine\JsonMachine; | ||||||
| use ZipArchive; | use ZipArchive; | ||||||
| 
 |  | ||||||
| use function GuzzleHttp\json_encode; | use function GuzzleHttp\json_encode; | ||||||
| 
 | 
 | ||||||
| class CompanyImport implements ShouldQueue | class CompanyImport implements ShouldQueue | ||||||
| @ -122,6 +123,7 @@ class CompanyImport implements ShouldQueue | |||||||
|         'clients', |         'clients', | ||||||
|         'client_contacts', |         'client_contacts', | ||||||
|         'vendors', |         'vendors', | ||||||
|  |         'vendor_contacts', | ||||||
|         'projects', |         'projects', | ||||||
|         'products', |         'products', | ||||||
|         'company_gateways', |         'company_gateways', | ||||||
| @ -147,6 +149,8 @@ class CompanyImport implements ShouldQueue | |||||||
|         'documents', |         'documents', | ||||||
|         'webhooks', |         'webhooks', | ||||||
|         'system_logs', |         'system_logs', | ||||||
|  |         'purchase_orders', | ||||||
|  |         'purchase_order_invitations' | ||||||
|     ]; |     ]; | ||||||
| 
 | 
 | ||||||
|     private $company_properties = [ |     private $company_properties = [ | ||||||
| @ -454,7 +458,7 @@ class CompanyImport implements ShouldQueue | |||||||
|         $settings->ticket_number_counter = 1; |         $settings->ticket_number_counter = 1; | ||||||
|         $settings->payment_number_counter = 1; |         $settings->payment_number_counter = 1; | ||||||
|         $settings->project_number_counter = 1; |         $settings->project_number_counter = 1; | ||||||
| 
 |         $settings->purchase_order_counter = 1; | ||||||
|         $this->company->settings = $co->settings; |         $this->company->settings = $co->settings; | ||||||
|         // $this->company->settings = $this->backup_file->company->settings;
 |         // $this->company->settings = $this->backup_file->company->settings;
 | ||||||
|         $this->company->save(); |         $this->company->save(); | ||||||
| @ -471,6 +475,7 @@ class CompanyImport implements ShouldQueue | |||||||
|         $this->company->vendors()->forceDelete(); |         $this->company->vendors()->forceDelete(); | ||||||
|         $this->company->expenses()->forceDelete(); |         $this->company->expenses()->forceDelete(); | ||||||
|         $this->company->subscriptions()->forceDelete(); |         $this->company->subscriptions()->forceDelete(); | ||||||
|  |         $this->company->purchase_orders()->forceDelete(); | ||||||
| 
 | 
 | ||||||
|         $this->company->save(); |         $this->company->save(); | ||||||
| 
 | 
 | ||||||
| @ -649,6 +654,19 @@ class CompanyImport implements ShouldQueue | |||||||
|         return $this; |         return $this; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     private function import_vendor_contacts() | ||||||
|  |     { | ||||||
|  | 
 | ||||||
|  |         $this->genericImport(VendorContact::class,  | ||||||
|  |             ['user_id', 'company_id', 'id', 'hashed_id','company','assigned_user_id'],  | ||||||
|  |             [['users' => 'user_id'], ['vendors' => 'vendor_id']],  | ||||||
|  |             'vendor_contacts', | ||||||
|  |             'email'); | ||||||
|  | 
 | ||||||
|  |         return $this; | ||||||
|  |          | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     private function import_projects() |     private function import_projects() | ||||||
|     { |     { | ||||||
| 
 | 
 | ||||||
| @ -796,6 +814,42 @@ class CompanyImport implements ShouldQueue | |||||||
|         return $this;         |         return $this;         | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     private function import_purchase_orders() | ||||||
|  |     { | ||||||
|  | 
 | ||||||
|  |         $this->genericImport(PurchaseOrder::class,  | ||||||
|  |             ['user_id', 'company_id', 'id', 'hashed_id', 'recurring_id','status', 'vendor_id', 'subscription_id','client_id'],  | ||||||
|  |             [ | ||||||
|  |                 ['users' => 'user_id'],  | ||||||
|  |                 ['users' => 'assigned_user_id'],  | ||||||
|  |                 ['recurring_invoices' => 'recurring_id'], | ||||||
|  |                 ['projects' => 'project_id'], | ||||||
|  |                 ['vendors' => 'vendor_id'], | ||||||
|  |             ],  | ||||||
|  |             'purchase_orders', | ||||||
|  |             'number'); | ||||||
|  | 
 | ||||||
|  |         return $this;         | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private function import_purchase_order_invitations() | ||||||
|  |     { | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |         $this->genericImport(PurchaseOrderInvitation::class,  | ||||||
|  |             ['user_id', 'vendor_contact_id', 'company_id', 'id', 'hashed_id', 'purchase_order_id'],  | ||||||
|  |             [ | ||||||
|  |                 ['users' => 'user_id'],  | ||||||
|  |                 ['purchase_orders' => 'purchase_order_id'], | ||||||
|  |                 ['vendor_contacts' => 'vendor_contact_id'], | ||||||
|  |             ],  | ||||||
|  |             'purchase_order_invitations', | ||||||
|  |             'key'); | ||||||
|  | 
 | ||||||
|  |         return $this;         | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|     private function import_quotes() |     private function import_quotes() | ||||||
|     { |     { | ||||||
| 
 | 
 | ||||||
| @ -1425,6 +1479,13 @@ class CompanyImport implements ShouldQueue | |||||||
|                 $new_obj->save(['timestamps' => false]); |                 $new_obj->save(['timestamps' => false]); | ||||||
|                 $new_obj->number = $this->getNextInvoiceNumber($client = Client::withTrashed()->find($obj_array['client_id']),$new_obj); |                 $new_obj->number = $this->getNextInvoiceNumber($client = Client::withTrashed()->find($obj_array['client_id']),$new_obj); | ||||||
|             } |             } | ||||||
|  |             elseif($class == 'App\Models\PurchaseOrder' && is_null($obj->{$match_key})){ | ||||||
|  |                 $new_obj = new PurchaseOrder(); | ||||||
|  |                 $new_obj->company_id = $this->company->id; | ||||||
|  |                 $new_obj->fill($obj_array); | ||||||
|  |                 $new_obj->save(['timestamps' => false]); | ||||||
|  |                 $new_obj->number = $this->getNextPurchaseOrderNumber($new_obj); | ||||||
|  |             } | ||||||
|             elseif($class == 'App\Models\Payment' && is_null($obj->{$match_key})){ |             elseif($class == 'App\Models\Payment' && is_null($obj->{$match_key})){ | ||||||
|                 $new_obj = new Payment(); |                 $new_obj = new Payment(); | ||||||
|                 $new_obj->company_id = $this->company->id; |                 $new_obj->company_id = $this->company->id; | ||||||
| @ -1445,6 +1506,12 @@ class CompanyImport implements ShouldQueue | |||||||
|                 $new_obj->fill($obj_array); |                 $new_obj->fill($obj_array); | ||||||
|                 $new_obj->save(['timestamps' => false]); |                 $new_obj->save(['timestamps' => false]); | ||||||
|             } |             } | ||||||
|  |             elseif($class == 'App\Models\VendorContact'){ | ||||||
|  |                 $new_obj = new VendorContact(); | ||||||
|  |                 $new_obj->company_id = $this->company->id; | ||||||
|  |                 $new_obj->fill($obj_array); | ||||||
|  |                 $new_obj->save(['timestamps' => false]); | ||||||
|  |             } | ||||||
|             elseif($class == 'App\Models\RecurringExpense' && is_null($obj->{$match_key})){ |             elseif($class == 'App\Models\RecurringExpense' && is_null($obj->{$match_key})){ | ||||||
|                 $new_obj = new RecurringExpense(); |                 $new_obj = new RecurringExpense(); | ||||||
|                 $new_obj->company_id = $this->company->id; |                 $new_obj->company_id = $this->company->id; | ||||||
| @ -1466,6 +1533,13 @@ class CompanyImport implements ShouldQueue | |||||||
|                 $new_obj->save(['timestamps' => false]); |                 $new_obj->save(['timestamps' => false]); | ||||||
|                 $new_obj->number = $this->getNextTaskNumber($new_obj);    |                 $new_obj->number = $this->getNextTaskNumber($new_obj);    | ||||||
|             } |             } | ||||||
|  |             elseif($class == 'App\Models\Vendor' && is_null($obj->{$match_key})){ | ||||||
|  |                 $new_obj = new Vendor(); | ||||||
|  |                 $new_obj->company_id = $this->company->id; | ||||||
|  |                 $new_obj->fill($obj_array); | ||||||
|  |                 $new_obj->save(['timestamps' => false]); | ||||||
|  |                 $new_obj->number = $this->getNextVendorNumber($new_obj);    | ||||||
|  |             } | ||||||
|             elseif($class == 'App\Models\CompanyLedger'){ |             elseif($class == 'App\Models\CompanyLedger'){ | ||||||
|                 $new_obj = $class::firstOrNew( |                 $new_obj = $class::firstOrNew( | ||||||
|                         [$match_key => $obj->{$match_key}, 'company_id' => $this->company->id], |                         [$match_key => $obj->{$match_key}, 'company_id' => $this->company->id], | ||||||
|  | |||||||
| @ -32,7 +32,6 @@ class PurchaseOrder extends BaseModel | |||||||
|     protected $fillable = [ |     protected $fillable = [ | ||||||
|         'number', |         'number', | ||||||
|         'discount', |         'discount', | ||||||
|         'company_id', |  | ||||||
|         'status_id', |         'status_id', | ||||||
|         'last_sent_date', |         'last_sent_date', | ||||||
|         'is_deleted', |         'is_deleted', | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user