Removed obsolete complete parameter.
[fa-stable.git] / admin / db / voiding_db.inc
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 include_once($path_to_root . "/sales/includes/sales_db.inc");
13 include_once($path_to_root . "/purchasing/includes/purchasing_db.inc");
14 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
15 include_once($path_to_root . "/manufacturing/includes/manufacturing_db.inc");
16
17 function void_transaction($type, $type_no, $date_, $memo_)
18 {
19         global $Refs;
20         $void_entry = get_voided_entry($type, $type_no);
21
22         if ($void_entry != null)
23                 return false;
24
25         switch ($type) {
26                 case ST_JOURNAL : // it's a journal entry
27                         if (!exists_gl_trans($type, $type_no))
28                                 return false;
29                         void_journal_trans($type, $type_no);
30                         break;
31
32                 case ST_BANKPAYMENT : // it's a payment
33                 case ST_BANKDEPOSIT : // it's a deposit
34                 case ST_BANKTRANSFER : // it's a transfer
35                         if (!exists_bank_trans($type, $type_no))
36                                 return false;
37                         void_bank_trans($type, $type_no);
38                         break;
39
40                 case ST_SALESINVOICE : // it's a customer invoice
41                 case ST_CUSTCREDIT : // it's a customer credit note
42                 case ST_CUSTPAYMENT : // it's a customer payment
43                 case ST_CUSTDELIVERY : // it's a customer dispatch
44                         if (!exists_customer_trans($type, $type_no))
45                                 return false;
46                         if ($type == ST_CUSTDELIVERY)   // added 04 Oct 2008 by Joe Hunt. If delivery note has a not voided invoice, then NO.
47                         {
48                                 $delivery = get_customer_trans($type_no, $type);
49                                 if ($delivery['trans_link'] != 0)
50                                 {
51                                         if (get_voided_entry(ST_SALESINVOICE, $delivery['trans_link']) === false)
52                                                 return false;
53                                 }
54                         }       
55                         post_void_customer_trans($type, $type_no);
56                         break;
57
58                 case ST_LOCTRANSFER : // it's a stock transfer
59                         if (get_stock_transfer_items($type_no) == null)
60                                 return false;
61                         void_stock_transfer($type_no);
62                         break;
63
64                 case ST_INVADJUST : // it's a stock adjustment
65                         if (get_stock_adjustment_items($type_no) == null)
66                                 return false;
67                         void_stock_adjustment($type_no);
68                         break;
69
70                 case ST_PURCHORDER : // it's a PO
71                 case ST_SUPPRECEIVE : // it's a GRN
72                         return false;
73                 case ST_SUPPINVOICE : // it's a suppler invoice
74                 case ST_SUPPCREDIT : // it's a supplier credit note
75                 case ST_SUPPAYMENT : // it's a supplier payment
76                         if (!exists_supp_trans($type, $type_no))
77                                 return false;
78                         if (!post_void_supp_trans($type, $type_no))
79                                 return false;
80                         break;
81
82                 case ST_WORKORDER : // it's a work order
83                         if (!get_work_order($type_no, true))
84                                 return false;
85                         void_work_order($type_no);
86                         break;
87
88                 case ST_MANUISSUE : // it's a work order issue
89                         if (!exists_work_order_issue($type_no))
90                                 return false;
91                         void_work_order_issue($type_no);
92                         break;
93
94                 case ST_MANURECEIVE : // it's a work order production
95                         if (!exists_work_order_produce($type_no))
96                                 return false;
97                         void_work_order_produce($type_no);
98                         break;
99
100                 case ST_SALESORDER: // it's a sales order
101                 case ST_SALESQUOTE: // it's a sales quotation
102                         return false;
103
104                 case ST_COSTUPDATE : // it's a stock cost update
105                         return false;
106                         break;
107         }
108
109         // only add an entry if it's actually been voided
110         add_audit_trail($type, $type_no, $date_, _("Voided.")."\n".$memo_);
111         add_voided_entry($type, $type_no, $date_, $memo_);
112         $Refs->restore_last($type, $type_no);
113         return true;
114 }
115
116 //--------------------------------------------------------------------------------------------------
117
118 function get_voided_entry($type, $type_no)
119 {
120         $sql = "SELECT * FROM ".TB_PREF."voided WHERE type=".db_escape($type)
121                 ." AND id=".db_escape($type_no);
122
123         $result = db_query($sql, "could not query voided transaction table");
124
125         return db_fetch($result);
126 }
127
128 //--------------------------------------------------------------------------------------------------
129
130 function add_voided_entry($type, $type_no, $date_, $memo_)
131 {
132         $date = date2sql($date_);
133         $sql = "INSERT INTO ".TB_PREF."voided (type, id, date_, memo_)
134                 VALUES (".db_escape($type).", ".db_escape($type_no).", "
135                 .db_escape($date).", ".db_escape($memo_).")";
136
137         db_query($sql, "could not add voided transaction entry");
138 }
139
140 //--------------------------------------------------------------------------------------------------
141
142 ?>