/** * Create invoice when estimate is accepted. * @param object $doc estimate or invoice object * @return int cloned invoice id. */ public static function create_payment_when_invoice_marked_as_paid($doc) { if (!is_a($doc, 'SI_Invoice')) { return; } // Check if status changed was to approved. if ($doc->get_status() != SI_Invoice::STATUS_PAID) { return; } $balance = $doc->get_balance(); if ($balance < 0.01) { return; } SI_Admin_Payment::create_admin_payment($doc->get_id(), $balance, '', 'Now', self::__('This payment was automatically added to settle the balance after it was marked as "Paid".')); }