diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 4374fb0d91..ccc4dc350e 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -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}"); diff --git a/app/Console/Commands/CreateSingleAccount.php b/app/Console/Commands/CreateSingleAccount.php index 8a6db25176..155d92a1d9 100644 --- a/app/Console/Commands/CreateSingleAccount.php +++ b/app/Console/Commands/CreateSingleAccount.php @@ -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 = []; diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index c9cca86dfe..78d0742cab 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -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}"); + } }