36fb7d876ba2c6667b3c8e7265ca8c70764453e9
[fa-stable.git] / admin / db / voiding_db.inc
1 <?php
2
3 include_once($path_to_root . "/sales/includes/sales_db.inc");
4 include_once($path_to_root . "/purchasing/includes/purchasing_db.inc");
5 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
6 include_once($path_to_root . "/manufacturing/includes/manufacturing_db.inc");
7
8 function void_transaction($type, $type_no, $date_, $memo_)
9 {
10         $void_entry = get_voided_entry($type, $type_no);
11
12         if ($void_entry != null)
13                 return false;
14
15         switch ($type) {
16                 case 0 : // it's a journal entry
17                         if (!exists_gl_trans($type, $type_no))
18                                 return false;
19                         void_gl_trans($type, $type_no);
20                         if (exists_bank_trans($type, $type_no))
21                                 void_bank_trans($type, $type_no);
22                         break;
23
24                 case 1 : // it's a payment
25                 case 2 : // it's a deposit
26                 case 4 : // it's a transfer
27                         if (!exists_bank_trans($type, $type_no))
28                                 return false;
29                         void_bank_trans($type, $type_no);
30                         break;
31
32                 case 10 : // it's a customer invoice
33                 case 11 : // it's a customer credit note
34                 case 12 : // it's a customer payment
35                         if (!exists_customer_trans($type, $type_no))
36                                 return false;
37                         post_void_customer_trans($type, $type_no);
38                         break;
39
40                 case systypes::location_transfer() : // it's a stock transfer
41                         if (get_stock_transfer_items($type_no) == null)
42                                 return false;
43                         void_stock_transfer($type_no);
44                         break;
45
46                 case systypes::inventory_adjustment() : // it's a stock adjustment
47                         if (get_stock_adjustment_items($type_no) == null)
48                                 return false;
49                         void_stock_adjustment($type_no);
50                         break;
51
52                 case 20 : // it's a suppler invoice
53                 case 21 : // it's a supplier credit note
54                 case 22 : // it's a supplier payment
55                 case 25 : // it's a GRN
56                         if (!exists_supp_trans($type, $type_no))
57                                 return false;
58                         if (!post_void_supp_trans($type, $type_no))
59                                 return false;
60                         break;
61
62                 case systypes::work_order() : // it's a work order
63                         if (!get_work_order($type_no, true))
64                                 return false;
65                         void_work_order($type_no);
66                         break;
67
68                 case 28 : // it's a work order issue
69                         if (!exists_work_order_issue($type_no))
70                                 return false;
71                         void_work_order_issue($type_no);
72                         break;
73
74                 case 29 : // it's a work order production
75                         if (!exists_work_order_produce($type_no))
76                                 return false;
77                         void_work_order_produce($type_no);
78                         break;
79
80                 case systypes::cost_update() : // it's a stock cost update
81                         break;
82         }
83
84         // only add an entry if it's actually been voided
85         add_voided_entry($type, $type_no, $date_, $memo_);
86
87         return true;
88 }
89
90 //--------------------------------------------------------------------------------------------------
91
92 function get_voided_entry($type, $type_no)
93 {
94         $sql = "SELECT * FROM ".TB_PREF."voided WHERE type=$type AND id=$type_no";
95
96         $result = db_query($sql, "could not query voided transaction table");
97
98         return db_fetch($result);
99 }
100
101 //--------------------------------------------------------------------------------------------------
102
103 function add_voided_entry($type, $type_no, $date_, $memo_)
104 {
105         $date = date2sql($date_);
106         $sql = "INSERT INTO ".TB_PREF."voided (type, id, date_, memo_)
107                 VALUES ($type, $type_no, '$date', '$memo_')";
108
109         db_query($sql, "could not add voided transaction entry");
110 }
111
112 //--------------------------------------------------------------------------------------------------
113
114 ?>