diff --git a/app/Factory/CreditFactory.php b/app/Factory/CreditFactory.php new file mode 100644 index 000000000000..2c4a59787b4c --- /dev/null +++ b/app/Factory/CreditFactory.php @@ -0,0 +1,53 @@ +status_id = Credit::STATUS_DRAFT; + $credit->number = null; + $credit->discount = 0; + $credit->is_amount_discount = true; + $credit->po_number = ''; + $credit->footer = ''; + $credit->terms = ''; + $credit->public_notes = ''; + $credit->private_notes = ''; + $credit->date = null; + $credit->due_date = null; + $credit->partial_due_date = null; + $credit->is_deleted = false; + $credit->line_items = json_encode([]); + $credit->backup = json_encode([]); + $credit->tax_name1 = ''; + $credit->tax_rate1 = 0; + $credit->tax_name2 = ''; + $credit->tax_rate2 = 0; + $credit->custom_value1 = 0; + $credit->custom_value2 = 0; + $credit->custom_value3 = 0; + $credit->custom_value4 = 0; + $credit->amount = 0; + $credit->balance = 0; + $credit->partial = 0; + $credit->user_id = $user_id; + $credit->company_id = $company_id; + $credit->recurring_id = null; + + return $credit; + } +} diff --git a/app/Factory/InvoiceItemFactory.php b/app/Factory/InvoiceItemFactory.php index 9848c8ba9e51..24bb555db400 100644 --- a/app/Factory/InvoiceItemFactory.php +++ b/app/Factory/InvoiceItemFactory.php @@ -68,7 +68,7 @@ class InvoiceItemFactory $item->custom_value3 = $faker->realText(10); $item->custom_value4 = $faker->realText(10); $item->tax_name1 = 'GST'; - $item->tax_rate1 = '10.00'; + $item->tax_rate1 = 10.00; $data[] = $item; } diff --git a/app/Repositories/CreditRepository.php b/app/Repositories/CreditRepository.php new file mode 100644 index 000000000000..e1974936a6ff --- /dev/null +++ b/app/Repositories/CreditRepository.php @@ -0,0 +1,49 @@ +credit_repo = $credit_repo; + + } + public function getClassName() { return Payment::class; @@ -46,7 +56,8 @@ class PaymentRepository extends BaseRepository $payment->status_id = Payment::STATUS_COMPLETED; $payment->save(); - if ($request->has('invoices')) { + if ($request->input('invoices')) { + \Log::error('invoices found'); $invoices = Invoice::whereIn('id', array_column($request->input('invoices'), 'id'))->company()->get(); $payment->invoices()->saveMany($invoices); @@ -104,11 +115,22 @@ class PaymentRepository extends BaseRepository if($request->has('invoices')){ foreach($request->input('invoices') as $adjusted_invoice) { + $invoice = Invoice::whereId($adjusted_invoice['id'])->company()->first(); $invoice_total_adjustment += $adjusted_invoice['amount']; - if(!array_key_exists('credit', $adjusted_invoice)){ - //todo - generate Credit Note for $amount on $invoice - the assumption here is that it is a FULL refund + if(array_key_exists('credits', $adjusted_invoice)){ + + //process and insert credit notes + foreach($adjusted_invoice['credits'] as $credit){ + + $credit = $this->credit_repo->save($credit, ); + + } + + } + else { + //todo - generate Credit Note for $amount on $invoice - the assumption here is that it is a FULL refund } }