1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Fixes for creating single account

This commit is contained in:
= 2020-10-21 14:10:32 +11:00
parent aa0735bb3d
commit a0b269ce99
3 changed files with 45 additions and 28 deletions

View File

@ -112,7 +112,7 @@ class CheckData extends Command
->subject('Check-Data: '.strtoupper($this->isValid ? Account::RESULT_SUCCESS : Account::RESULT_FAILURE)." [{$database}]");
});
} elseif (! $this->isValid) {
throw new Exception("Check data failed!!\n".$this->log);
new Exception("Check data failed!!\n".$this->log);
}
}
@ -322,7 +322,8 @@ class CheckData extends Command
$total_invoice_payments = 0;
foreach ($client->invoices as $invoice) {
$total_amount = $invoice->payments->sum('pivot.amount');
info(print_r($invoice->payments,1));
$total_amount = $invoice->payments->sum('pivot.amount'); // the problem with this is that this also will sum the credits
$total_refund = $invoice->payments->sum('pivot.refunded');
$total_invoice_payments += ($total_amount - $total_refund);
@ -333,7 +334,7 @@ class CheckData extends Command
$credit_total_applied += $payment->paymentables->where('paymentable_type', App\Models\Credit::class)->sum(\DB::raw('amount'));
}
$total_invoice_payments += $credit_total_applied; //todo this is contentious
//$total_invoice_payments += $credit_total_applied; //todo this is contentious
info("total invoice payments = {$total_invoice_payments} with client paid to date of of {$client->paid_to_date}");

View File

@ -203,6 +203,10 @@ class CreateSingleAccount extends Command
$this->info('creating project for client #'.$client->id);
$this->createProject($client);
$this->info('creating credit for client #'.$client->id);
$this->createCredit($client);
}
$this->createGateways($company, $user);
@ -344,11 +348,6 @@ class CreateSingleAccount extends Command
private function createCredit($client)
{
// for($x=0; $x<$this->count; $x++){
// dispatch(new CreateTestCreditJob($client));
// }
$faker = \Faker\Factory::create();
$credit = Credit::factory()->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]);
@ -356,24 +355,9 @@ class CreateSingleAccount extends Command
$dateable = Carbon::now()->subDays(rand(0, 90));
$credit->date = $dateable;
$credit->line_items = $this->buildLineItems(rand(1, 10));
$credit->line_items = $this->buildCreditItem();
$credit->uses_inclusive_taxes = false;
if (rand(0, 1)) {
$credit->tax_name1 = 'GST';
$credit->tax_rate1 = 10.00;
}
if (rand(0, 1)) {
$credit->tax_name2 = 'VAT';
$credit->tax_rate2 = 17.50;
}
if (rand(0, 1)) {
$credit->tax_name3 = 'CA Sales Tax';
$credit->tax_rate3 = 5;
}
$credit->save();
$invoice_calc = new InvoiceSum($credit);
@ -428,6 +412,32 @@ class CreateSingleAccount extends Command
$quote->service()->createInvitations();
}
private function buildCreditItem()
{
$line_items = [];
$item = InvoiceItemFactory::create();
$item->quantity = 1;
$item->cost = 1000;
$product = Product::all()->random();
$item->cost = (float) $product->cost;
$item->product_key = $product->product_key;
$item->notes = $product->notes;
$item->custom_value1 = $product->custom_value1;
$item->custom_value2 = $product->custom_value2;
$item->custom_value3 = $product->custom_value3;
$item->custom_value4 = $product->custom_value4;
$line_items[] = $item;
return $line_items;
}
private function buildLineItems($count = 1)
{
$line_items = [];

View File

@ -77,6 +77,9 @@ class PaymentRepository extends BaseRepository
$this->processExchangeRates($data, $payment);
$is_existing_payment = false;
$client = Client::find($data['client_id']);
info("client paid to date {$client->paid_to_date}");
/*We only update the paid to date ONCE per payment*/
if (array_key_exists('invoices', $data) && is_array($data['invoices']) && count($data['invoices']) > 0) {
@ -84,16 +87,19 @@ class PaymentRepository extends BaseRepository
$data['amount'] = array_sum(array_column($data['invoices'], 'amount'));
}
$client = Client::find($data['client_id']);
$client->service()->updatePaidToDate($data['amount'])->save();
info("client paid to date {$client->paid_to_date}");
}
//todo
if (array_key_exists('credits', $data) && is_array($data['credits']) && count($data['credits']) > 0) {
if ($data['amount'] == '') {
$data['amount'] += array_sum(array_column($data['credits'], 'amount'));
$data['amount'] -= array_sum(array_column($data['credits'], 'amount'));
}
info("client paid to date {$client->paid_to_date}");
}
}