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