4ff6854973bfa79bd7168ff33e382767bb6b7a11
[fa-stable.git] / sales / includes / db / recurrent_invoices_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
13 function add_recurrent_invoice($description, $order_no, $debtor_no, $group_no, $days, $monthly,
14         $begin, $end)
15 {
16         $sql = "INSERT INTO ".TB_PREF."recurrent_invoices (description, order_no, debtor_no,
17                 group_no, days, monthly, begin, end, last_sent) VALUES (".db_escape($description) . ", "
18                 .db_escape($order_no).", ".db_escape($debtor_no).", "
19                 .db_escape($group_no).", ".$days.", ".$monthly.", '"
20                 .date2sql($begin)."', '".date2sql($end)."', '".date2sql(Add_Years($begin, -5))."')";
21         db_query($sql,"The recurrent invoice could not be added");
22 }
23
24 function update_recurrent_invoice($selected_id, $description, $order_no, $debtor_no, $group_no, $days, $monthly,
25         $begin, $end)
26 {
27         $sql = "UPDATE ".TB_PREF."recurrent_invoices SET 
28                 description=".db_escape($description).", 
29                 order_no=".db_escape($order_no).", 
30                 debtor_no=".db_escape($debtor_no).", 
31                 group_no=".db_escape($group_no).", 
32                 days=".$days.", 
33                 monthly=".$monthly.", 
34                 begin='".date2sql($begin)."', 
35                 end='".date2sql($end)."' 
36                 WHERE id = ".db_escape($selected_id);
37         db_query($sql,"The recurrent invoice could not be updated");
38 }
39
40 function update_last_sent_recurrent_invoice($id, $date)
41 {
42         $date = date2sql($date);
43         $sql = "UPDATE ".TB_PREF."recurrent_invoices SET last_sent='$date' WHERE id=".db_escape($id);
44         db_query($sql,"The recurrent invoice could not be updated");
45 }
46
47 function delete_recurrent_invoice($selected_id)
48 {
49         $sql="DELETE FROM ".TB_PREF."recurrent_invoices WHERE id=".db_escape($selected_id);
50         db_query($sql,"could not delete recurrent invoice");
51 }
52
53 function get_recurrent_invoices()
54 {
55         $sql = "SELECT * FROM ".TB_PREF."recurrent_invoices ORDER BY description, group_no, debtor_no";
56         return db_query($sql,"could not get recurrent invoices");
57 }
58
59 function get_recurrent_invoice($selected_id)
60 {
61         $sql = "SELECT * FROM ".TB_PREF."recurrent_invoices WHERE id=".db_escape($selected_id);
62
63         $result = db_query($sql,"could not get recurrent invoice");
64         return db_fetch($result);
65 }
66 ?>