Can't void customer payment if there is an invoice with same number that has been...
[fa-stable.git] / admin / db / voiding_db.inc
index 55ff9fb9079a587c4c9205248581fb34ad2b6d65..86b452edb87d66ecc1623cd68058f1875b24f774 100644 (file)
@@ -45,7 +45,7 @@ function void_transaction($type, $type_no, $date_, $memo_)
                        if (!check_void_bank_trans($type, $type_no))
                                return _('This transaction cannot be voided because the operation would decrease account balance below allowed limit in some point of account history.');
                case ST_SALESINVOICE : // it's a customer invoice
-                       if (is_cust_invoice_credited($type_no))
+                       if (is_cust_invoice_credited($type_no) && $type == ST_SALES_INVOICE)
                                return _('This invoice cannot be voided because it was already credited.');
                case ST_CUSTCREDIT : // it's a customer credit note
                case ST_CUSTDELIVERY : // it's a customer dispatch
@@ -53,9 +53,12 @@ function void_transaction($type, $type_no, $date_, $memo_)
                                return _('Selected transaction does not exists.');
                        if ($type == ST_CUSTDELIVERY)   // added 04 Oct 2008 by Joe Hunt. If delivery note has a not voided invoice, then NO.
                        {
-                               $childs = get_sales_child_lines($type, $type_no, false); // 2011-03-17 This had been changed. Joe
-                               if ($childs && db_num_rows($childs))
-                                       return _('This delivery cannot be voided because it was already invoiced.');
+                               $vers = get_customer_trans_version($type, $type_no);
+                               if ($vers[$type_no] == 1) {
+                                       $childs = get_sales_child_lines($type, $type_no, false); // 2011-03-17 This had been changed. Joe
+                                       if ($childs && db_num_rows($childs))
+                                               return _('This delivery cannot be voided because it was already invoiced.');
+                               }
                        }
                        post_void_customer_trans($type, $type_no);
                        break;