[000009] Delivery Note/Sales Invoice should not be editable after it has been voided.
[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                         if ($type == 13)        // added 04 Oct 2008 by Joe Hunt. If delivery note has a not voided invoice, then NO.
39                         {
40                                 $delivery = get_customer_trans($type_no, $type);
41                                 if ($delivery['trans_link'] != 0)
42                                 {
43                                         if (get_voided_entry(10, $delivery['trans_link']) === false)
44                                                 return false;
45                                 }
46                         }       
47                         post_void_customer_trans($type, $type_no);
48                         break;
49
50                 case systypes::location_transfer() : // it's a stock transfer
51                         if (get_stock_transfer_items($type_no) == null)
52                                 return false;
53                         void_stock_transfer($type_no);
54                         break;
55
56                 case systypes::inventory_adjustment() : // it's a stock adjustment
57                         if (get_stock_adjustment_items($type_no) == null)
58                                 return false;
59                         void_stock_adjustment($type_no);
60                         break;
61
62                 case 25 : // it's a GRN
63                         return false;
64                 case 20 : // it's a suppler invoice
65                 case 21 : // it's a supplier credit note
66                 case 22 : // it's a supplier payment
67                         if (!exists_supp_trans($type, $type_no))
68                                 return false;
69                         if (!post_void_supp_trans($type, $type_no))
70                                 return false;
71                         break;
72
73                 case systypes::work_order() : // it's a work order
74                         if (!get_work_order($type_no, true))
75                                 return false;
76                         void_work_order($type_no);
77                         break;
78
79                 case 28 : // it's a work order issue
80                         if (!exists_work_order_issue($type_no))
81                                 return false;
82                         void_work_order_issue($type_no);
83                         break;
84
85                 case 29 : // it's a work order production
86                         if (!exists_work_order_produce($type_no))
87                                 return false;
88                         void_work_order_produce($type_no);
89                         break;
90
91                 case systypes::cost_update() : // it's a stock cost update
92                         return false;
93                         break;
94         }
95
96         // only add an entry if it's actually been voided
97         add_voided_entry($type, $type_no, $date_, $memo_);
98
99         return true;
100 }
101
102 //--------------------------------------------------------------------------------------------------
103
104 function get_voided_entry($type, $type_no)
105 {
106         $sql = "SELECT * FROM ".TB_PREF."voided WHERE type=$type AND id=$type_no";
107
108         $result = db_query($sql, "could not query voided transaction table");
109
110         return db_fetch($result);
111 }
112
113 //--------------------------------------------------------------------------------------------------
114
115 function add_voided_entry($type, $type_no, $date_, $memo_)
116 {
117         $date = date2sql($date_);
118         $sql = "INSERT INTO ".TB_PREF."voided (type, id, date_, memo_)
119                 VALUES ($type, $type_no, ".db_escape($date).", ".db_escape($memo_).")";
120
121         db_query($sql, "could not add voided transaction entry");
122 }
123
124 //--------------------------------------------------------------------------------------------------
125
126 ?>