1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 12:42:36 +01:00

Random migration datasets

This commit is contained in:
David Bomba 2020-11-25 11:23:51 +11:00
parent fdaf513267
commit ae52ea5971
3 changed files with 51 additions and 5 deletions

View File

@ -17,7 +17,7 @@ class ExportMigrations extends Command
*
* @var string
*/
protected $signature = 'migrations:export {--user=}';
protected $signature = 'migrations:export {--user=} {--random=}';
/**
* The console command description.
@ -50,6 +50,15 @@ class ExportMigrations extends Command
return $this->export($record);
}
if($this->option('random')){
User::all()->random(50)->each(function ($user){
$this->export($user);
});
return;
}
$users = User::all();
foreach($users as $user) {

View File

@ -245,6 +245,7 @@ class StepsController extends BaseController
'task_statuses' => $this->getTaskStatuses(),
'expenses' => $this->getExpenses(),
'tasks' => $this->getTasks(),
'documents' => $this->getDocuments(),
];
$localMigrationData['force'] = array_key_exists('force', $company) ? true : false;

View File

@ -354,11 +354,11 @@ trait GenerateMigrationResources
'custom_value1' => $credit->custom_value1 ?: '',
'custom_value2' => $credit->custom_value2 ?: '',
'next_send_date' => null,
'amount' => $credit->amount ?: 0,
'balance' => $credit->balance ?: 0,
'partial' => $credit->partial ?: 0,
'amount' => $credit->amount ? $credit->amount * -1: 0,
'balance' => $credit->balance ? $credit->balance * -1 : 0,
'partial' => $credit->partial ? $credit->partial * -1 : 0,
'partial_due_date' => $credit->partial_due_date,
'line_items' => $this->getInvoiceItems($credit->invoice_items),
'line_items' => $this->getCreditItems($credit->invoice_items),
'created_at' => $credit->created_at ? Carbon::parse($credit->created_at)->toDateString() : null,
'updated_at' => $credit->updated_at ? Carbon::parse($credit->updated_at)->toDateString() : null,
'deleted_at' => $credit->deleted_at ? Carbon::parse($credit->deleted_at)->toDateString() : null,
@ -752,6 +752,41 @@ trait GenerateMigrationResources
return $transformed;
}
public function getCreditItems($items)
{
$transformed = [];
foreach ($items as $item) {
if($item->cost < 0)
$item->cost = $item->cost * -1;
if($item->qty < 0)
$item->qty = $item->qty * -1;
$transformed[] = [
'id' => $item->id,
'quantity' => (float) $item->qty,
'cost' => (float) $item->cost,
'product_key' => $item->product_key,
'notes' => $item->notes,
'discount' => (float) $item->discount,
'tax_name1' => (string)$item->tax_name1,
'tax_rate1' => (float) $item->tax_rate1,
'tax_name2' => (string) $item->tax_name2,
'tax_rate2' => (float) $item->tax_rate2,
'tax_name3' => (string) '',
'tax_rate3' => (float) 0,
'date' => Carbon::parse($item->created_at)->toDateString(),
'custom_value1' => $item->custom_value1,
'custom_value2' => $item->custom_value2,
'type_id' => (string)$item->invoice_item_type_id,
];
}
return $transformed;
}
public function getInvoiceItems($items)
{
$transformed = [];
@ -958,6 +993,7 @@ trait GenerateMigrationResources
'height' => $document->height,
'created_at' => $document->created_at ? Carbon::parse($document->created_at)->toDateString() : null,
'updated_at' => $document->updated_at ? Carbon::parse($document->updated_at)->toDateString() : null,
'url' => $document->getUrl(),
];
}