Tax algorithm handling on supplier side is reverted as unpractical.
[fa-stable.git] / purchasing / includes / db / po_db.inc
index b33a2fa00b1556914d5f87b065a3a864a3d6b7d6..65a46c3188adc4d74e5d798c4cbcb15688e6d8a4 100644 (file)
@@ -9,16 +9,54 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
+// ------------------------------------------------------------------------------
+
+function get_supplier_details_to_order(&$order, $supplier_id)
+{
+       $sql = "SELECT curr_code, supp_name, tax_group_id, supp.tax_included,
+                       supp.credit_limit - Sum(IFNULL(IF(trans.type=".ST_SUPPCREDIT.", -1, 1) 
+                               * (ov_amount + ov_gst + ov_discount),0)) as cur_credit,
+                               terms.terms, terms.days_before_due, terms.day_in_following_month
+               FROM ".TB_PREF."suppliers supp
+                        LEFT JOIN ".TB_PREF."supp_trans trans ON supp.supplier_id = trans.supplier_id
+                        LEFT JOIN ".TB_PREF."payment_terms terms ON supp.payment_terms=terms.terms_indicator
+               WHERE supp.supplier_id = ".db_escape($supplier_id)."
+               GROUP BY
+                         supp.supp_name";
+
+       $result = db_query($sql, "The supplier details could not be retreived");
+       $myrow = db_fetch($result);
+
+       $order->credit = $myrow["cur_credit"];
+       $order->terms = array( 
+               'description' => $myrow['terms'],
+               'days_before_due' => $myrow['days_before_due'], 
+               'day_in_following_month' => $myrow['day_in_following_month'] );
+
+       $_POST['supplier_id'] = $supplier_id;
+       $_POST['supplier_name'] = $myrow["supp_name"];
+       $_POST['curr_code'] = $myrow["curr_code"];
+
+       $order->set_supplier($supplier_id, $myrow["supp_name"], $myrow["curr_code"], 
+               $myrow["tax_group_id"], $myrow["tax_included"]);
+}
+
 //----------------------------------------------------------------------------------------
 
 function delete_po($po)
 {
+       global $Refs;
+
+       begin_transaction();
        hook_db_prevoid($po, ST_PURCHORDER);
        $sql = "DELETE FROM ".TB_PREF."purch_orders WHERE order_no=".db_escape($po);
        db_query($sql, "The order header could not be deleted");
 
        $sql = "DELETE FROM ".TB_PREF."purch_order_details WHERE order_no =".db_escape($po);
        db_query($sql, "The order detail lines could not be deleted");
+
+       $Refs->restore_last(ST_PURCHORDER, $po);
+       commit_transaction();
 }
 
 //----------------------------------------------------------------------------------------
@@ -150,7 +188,7 @@ function read_po_header($order_no, &$order)
        $order->order_no = $order_no;
 
        $order->set_supplier($myrow["supplier_id"], $myrow["supp_name"], $myrow["curr_code"],
-               $myrow['tax_group_id'], $myrow["tax_included"], @$myrow["tax_algorithm"]);
+               $myrow['tax_group_id'], $myrow["tax_included"]);
 
                $order->credit = get_current_supp_credit($order->supplier_id);
 
@@ -261,7 +299,6 @@ function get_short_info($stock_id)
 function get_sql_for_po_search_completed($from, $to, $supplier_id=ALL_TEXT, $location=ALL_TEXT,
        $order_number = '', $stock_id = '')
 {
-
        $sql = "SELECT 
                porder.order_no, 
                porder.reference, 
@@ -282,7 +319,7 @@ function get_sql_for_po_search_completed($from, $to, $supplier_id=ALL_TEXT, $loc
 
        if ($supplier_id != ALL_TEXT)
                $sql .= "AND supplier.supplier_id=".$supplier_id." ";
-       if (isset($order_number) && $order_number != "")
+       if ($order_number != "")
        {
                $sql .= "AND porder.reference LIKE ".db_escape('%'. $order_number . '%');
        }
@@ -299,7 +336,7 @@ function get_sql_for_po_search_completed($from, $to, $supplier_id=ALL_TEXT, $loc
                {
                        $sql .= " AND porder.into_stock_location = ".db_escape($location);
                }
-               if (isset($selected_stock_item))
+               if ($stock_id !== '')
                {
                        $sql .= " AND line.item_code=".db_escape($stock_id);
                }
@@ -312,10 +349,8 @@ function get_sql_for_po_search_completed($from, $to, $supplier_id=ALL_TEXT, $loc
        return $sql;
 }
 
-function get_sql_for_po_search($from, $to, $supplier_id=ALL_TEXT, $location=ALL_TEXT)
+function get_sql_for_po_search($from, $to, $supplier_id=ALL_TEXT, $location=ALL_TEXT, $order_number='', $stock_id='')
 {
-       global $all_items, $order_number, $selected_stock_item;;
-       
        $sql = "SELECT 
                porder.order_no, 
                porder.reference,
@@ -337,7 +372,7 @@ function get_sql_for_po_search($from, $to, $supplier_id=ALL_TEXT, $location=ALL_
                AND location.loc_code = porder.into_stock_location
                AND (line.quantity_ordered > line.quantity_received) ";
 
-       if (isset($order_number) && $order_number != "")
+       if ($order_number != "")
        {
                $sql .= "AND porder.reference LIKE ".db_escape('%'. $order_number . '%');
        }
@@ -354,9 +389,9 @@ function get_sql_for_po_search($from, $to, $supplier_id=ALL_TEXT, $location=ALL_
                        $sql .= " AND porder.into_stock_location = ".db_escape($location);
                }
 
-               if (isset($selected_stock_item))
+               if ($stock_id != '')
                {
-                       $sql .= " AND line.item_code=".db_escape($selected_stock_item);
+                       $sql .= " AND line.item_code=".db_escape($stock_id);
                }
                if ($supplier_id != ALL_TEXT)
                        $sql .= " AND supplier.supplier_id=".db_escape($supplier_id);
@@ -366,4 +401,3 @@ function get_sql_for_po_search($from, $to, $supplier_id=ALL_TEXT, $location=ALL_
        return $sql;
 }
 
-?>
\ No newline at end of file