public static function GenerateCreditNote($clientid, $invoice, $items, $description) { $client = Client::GetClient($clientid); $description = 'Credit Note (Inv: ' . $invoice . ') - ' . $description; $credit = 0.0; foreach ($items as $item) { $invline = SalesInvoiceLine::GetLineItem($item[0]); $lamt = $item[1] * $invline->unitPrice; $credit += $lamt + $lamt * $invline->tax / 100; } $inv = SalesInvoice::GetInvoice($invoice); if ($inv->total->amount < $inv->credit->amount + $credit) { return false; } $crnote = CreditNote::CreateCreditNote($client, $invoice, $items, $description); if ($crnote->generate()) { return new SalesTX($crnote, 'Credit Note'); } else { Logger::Log('SalesTX', 'Failed', 'Credit Note transaction with id:' . $crnote->id . ' and tx id:' . $this->transactionId . ' could not be completed'); return false; } }