X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=purchasing%2Fincludes%2Fdb%2Fsuppalloc_db.inc;h=c8ad5c46adf137c0dbd920b495adf8e7d793f9c7;hb=128be63f9ae68744f37eae8072f95d0f524f86b4;hp=57e76b35fd23ca2ea23e132d842e93fd56ee5f4a;hpb=3b431d909abc53e4a4d712cbafa39ca556409d0e;p=fa-stable.git diff --git a/purchasing/includes/db/suppalloc_db.inc b/purchasing/includes/db/suppalloc_db.inc index 57e76b35..c8ad5c46 100644 --- a/purchasing/includes/db/suppalloc_db.inc +++ b/purchasing/includes/db/suppalloc_db.inc @@ -97,10 +97,6 @@ function clear_supp_alloctions($type, $type_no, $person_id=null, $date="") $sql .= " AND person_id=".db_escape($person_id); db_query($sql, "could not void supp transactions for type=$type and trans_no=$type_no"); -// is this necessary? -// if ($date != "") -// exchange_variation($type, $type_no, $row['trans_type_to'], $row['trans_no_to'], $date, -// $row['amt'], PT_SUPPLIER, true); } //------------------------------------------------------------------------------------------------------------- @@ -152,7 +148,8 @@ function get_allocatable_purch_orders($supplier_id = null, $trans_no=null, $type due_dates.date as due_date, supplier.address, amt, - requisition_no as supp_ref + supp_reference as supp_ref, + 0, 0 FROM ".TB_PREF."purch_orders as porder LEFT JOIN ".TB_PREF."suppliers as supplier ON porder.supplier_id = supplier.supplier_id LEFT JOIN ".TB_PREF."supp_allocations as alloc @@ -168,8 +165,6 @@ function get_allocatable_purch_orders($supplier_id = null, $trans_no=null, $type } else { -// FIXME: change to form below when prepayments terms finally can be selected in PO entry form: -// $sql .= " AND round(prep_amount) > 0 AND ISNULL(grn.purch_order_no)"; // only sales orders with prepayment level set and no yet received $sql .= " AND ISNULL(grn.purch_order_no)"; // only sales orders no yet received } if ($supplier_id) @@ -195,29 +190,31 @@ function get_allocatable_to_supp_transactions($supplier_id=null, $trans_no=null, trans.due_date, trans.supplier_id, amt, - supp_reference + supp_reference, + pmt.early_days, + pmt.early_discount FROM ".TB_PREF."supp_trans as trans + LEFT JOIN ".TB_PREF."suppliers supplier ON trans.supplier_id=supplier.supplier_id + LEFT JOIN ".TB_PREF."payment_terms as pmt ON supplier.payment_terms=pmt.id LEFT JOIN ".TB_PREF."supp_allocations as alloc - ON trans.trans_no = alloc.trans_no_to AND trans.type = alloc.trans_type_to AND alloc.person_id=trans.supplier_id," - .TB_PREF."suppliers as supplier - WHERE - trans.supplier_id=supplier.supplier_id"; - if ($supplier_id) - $sql .= " AND supplier.supplier_id=".db_escape($supplier_id); + ON trans.trans_no = alloc.trans_no_to AND trans.type = alloc.trans_type_to AND alloc.person_id=trans.supplier_id"; if ($trans_no != null and $type != null) { - $sql .= " AND alloc.trans_no_from=".db_escape($trans_no)." + $sql .= " WHERE alloc.trans_no_from=".db_escape($trans_no)." AND alloc.trans_type_from=".db_escape($type); } else { - $sql .= " AND round(ov_amount+ov_gst+ov_discount-alloc,6) > 0 + $sql .= " WHERE round(ov_amount+ov_gst+ov_discount-alloc,6) > 0 AND trans.type NOT IN (".implode(',',array(ST_SUPPAYMENT, ST_BANKPAYMENT)).")"; - $sql .= " GROUP BY type, trans_no"; } + if ($supplier_id) + $sql .= " AND supplier.supplier_id=".db_escape($supplier_id); + + $orders = get_allocatable_purch_orders($supplier_id, $trans_no, $type); $sql = "($sql ORDER BY trans_no) \nUNION \n($orders)"; @@ -261,7 +258,6 @@ function get_allocatable_from_supp_transactions($supplier_id, $trans_no=null, $t AND trans.type NOT IN (".implode(',',array(ST_SUPPAYMENT,ST_BANKPAYMENT)).")"; $sql .= " GROUP BY type, trans_no"; } -//_vd($sql); return db_query($sql." ORDER BY due_date", "Cannot retreive alloc to transactions"); }