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