Moving 2.0 development version to main trunk.
[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                 case 13 : // it's a customer dispatch
36                         if (!exists_customer_trans($type, $type_no))
37                                 return false;
38                         post_void_customer_trans($type, $type_no);
39                         break;
40
41                 case systypes::location_transfer() : // it's a stock transfer
42                         if (get_stock_transfer_items($type_no) == null)
43                                 return false;
44                         void_stock_transfer($type_no);
45                         break;
46
47                 case systypes::inventory_adjustment() : // it's a stock adjustment
48                         if (get_stock_adjustment_items($type_no) == null)
49                                 return false;
50                         void_stock_adjustment($type_no);
51                         break;
52
53                 case 25 : // it's a GRN
54                         return false;
55                 case 20 : // it's a suppler invoice
56                 case 21 : // it's a supplier credit note
57                 case 22 : // it's a supplier payment
58                         if (!exists_supp_trans($type, $type_no))
59                                 return false;
60                         if (!post_void_supp_trans($type, $type_no))
61                                 return false;
62                         break;
63
64                 case systypes::work_order() : // it's a work order
65                         if (!get_work_order($type_no, true))
66                                 return false;
67                         void_work_order($type_no);
68                         break;
69
70                 case 28 : // it's a work order issue
71                         if (!exists_work_order_issue($type_no))
72                                 return false;
73                         void_work_order_issue($type_no);
74                         break;
75
76                 case 29 : // it's a work order production
77                         if (!exists_work_order_produce($type_no))
78                                 return false;
79                         void_work_order_produce($type_no);
80                         break;
81
82                 case systypes::cost_update() : // it's a stock cost update
83                         return false;
84                         break;
85         }
86
87         // only add an entry if it's actually been voided
88         add_voided_entry($type, $type_no, $date_, $memo_);
89
90         return true;
91 }
92
93 //--------------------------------------------------------------------------------------------------
94
95 function get_voided_entry($type, $type_no)
96 {
97         $sql = "SELECT * FROM ".TB_PREF."voided WHERE type=$type AND id=$type_no";
98
99         $result = db_query($sql, "could not query voided transaction table");
100
101         return db_fetch($result);
102 }
103
104 //--------------------------------------------------------------------------------------------------
105
106 function add_voided_entry($type, $type_no, $date_, $memo_)
107 {
108         $date = date2sql($date_);
109         $sql = "INSERT INTO ".TB_PREF."voided (type, id, date_, memo_)
110                 VALUES ($type, $type_no, ".db_escape($date).", ".db_escape($memo_).")";
111
112         db_query($sql, "could not add voided transaction entry");
113 }
114
115 //--------------------------------------------------------------------------------------------------
116
117 ?>