Huge sales module changes toward delivery and invoicing separation. Includes some...
[fa-stable.git] / sales / includes / sales_db.inc
1 <?php
2
3 include_once($path_to_root . "/includes/banking.inc");
4
5 include_once($path_to_root . "/includes/db/inventory_db.inc");
6
7 include_once($path_to_root . "/sales/includes/db/sales_order_db.inc");
8 include_once($path_to_root . "/sales/includes/db/sales_credit_db.inc");
9 include_once($path_to_root . "/sales/includes/db/sales_invoice_db.inc");
10 include_once($path_to_root . "/sales/includes/db/sales_delivery_db.inc");
11 include_once($path_to_root . "/sales/includes/db/custalloc_db.inc");
12 include_once($path_to_root . "/sales/includes/db/cust_trans_db.inc");
13 include_once($path_to_root . "/sales/includes/db/cust_trans_details_db.inc");
14 include_once($path_to_root . "/sales/includes/db/payment_db.inc");
15 include_once($path_to_root . "/sales/includes/db/branches_db.inc");
16 include_once($path_to_root . "/sales/includes/db/customers_db.inc");
17
18
19 //----------------------------------------------------------------------------------------
20
21 // $price in customer's currency
22 // $quantity is used as is (if it's neg it's neg, if it's pos it's pos)
23 // $std_cost is in home currency
24 // $show_or_hide 1 show this item in invoice/credit views, 0 to hide it (used for write-off items)
25 // $type is 10 (invoice) or 11 (credit)
26
27 function add_stock_move_customer($type, $stock_id, $trans_id, $location, $date_, $reference, 
28         $quantity, $std_cost, $show_or_hide=1, $price=0, $discount_percent=0)
29 {
30         return add_stock_move($type, $stock_id, $trans_id, $location, $date_, $reference, 
31                 $quantity, $std_cost, 0, $show_or_hide, $price, $discount_percent, 
32                 "The customer stock movement record cannot be inserted");
33 }       
34
35 //----------------------------------------------------------------------------------------
36
37 // add a debtor-related gl transaction
38 // $date_ is display date (non-sql)
39 // $amount is in CUSTOMER'S currency
40
41 function add_gl_trans_customer($type, $type_no, $date_, $account, $dimension, $dimension2, 
42         $amount, $customer_id, $err_msg="")
43 {
44         if ($err_msg == "")
45                 $err_msg = "The customer GL transaction could not be inserted"; 
46                 
47         return add_gl_trans($type, $type_no, $date_, $account, $dimension, $dimension2, "", $amount, 
48                 get_customer_currency($customer_id), 
49                 payment_person_types::customer(), $customer_id, $err_msg);
50 }
51
52 //----------------------------------------------------------------------------------------
53
54 function get_price ($stock_id, $debtor_no)
55 {
56         $sql = "SELECT ".TB_PREF."prices.price 
57                 FROM ".TB_PREF."prices, ".TB_PREF."debtors_master 
58                 WHERE ".TB_PREF."debtors_master.sales_type=".TB_PREF."prices.sales_type_id
59                         AND ".TB_PREF."debtors_master.debtor_no='" . $debtor_no . "' 
60                         AND ".TB_PREF."prices.stock_id = '" . $stock_id . "' 
61                         AND ".TB_PREF."prices.curr_abrev = ".TB_PREF."debtors_master.curr_code";
62                                         
63         $result = db_query($sql, "There was a problem retrieving the pricing information for the part $stock_id for customer");
64
65         if (db_num_rows($result) != 0)
66         {
67                 /*There is a price from one of the above so return that */
68                 $myrow = db_fetch_row($result);
69                 return $myrow[0];
70         } 
71         else 
72         {
73                 return 0;
74         }
75                         
76 }
77
78 //----------------------------------------------------------------------------------------
79
80 ?>