X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=purchasing%2Fincludes%2Fdb%2Finvoice_db.inc;h=dd172395ef803e21ff414aaa1807d79634bb987b;hb=ae7f824b56286a83b547afc89ab3bbc26c5cc23c;hp=80169267ac9aa1a675adc14c84f1a6c5098fb5d7;hpb=1571869d54be48452fdbe08f25130972ff0a7b5a;p=fa-stable.git diff --git a/purchasing/includes/db/invoice_db.inc b/purchasing/includes/db/invoice_db.inc index 80169267..dd172395 100644 --- a/purchasing/includes/db/invoice_db.inc +++ b/purchasing/includes/db/invoice_db.inc @@ -200,12 +200,15 @@ function add_supp_invoice(&$supp_trans) // do not receive as ref because we chan $taxitem['tax_type_id'], $taxitem['rate'], $supp_trans->tax_included, $taxitem['Value'], $taxitem['Net'], $ex_rate, $date_, $supp_trans->supp_reference); - if ($trans_type == ST_SUPPCREDIT) - $taxitem['Value'] = -$taxitem['Value']; - $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, - $taxitem['purchasing_gl_code'], 0, 0, $taxitem['Value'], - $supp_trans->supplier_id, - "A general ledger transaction for the tax amount could not be added"); + if (isset($taxitem['purchasing_gl_code'])) + { + if ($trans_type == ST_SUPPCREDIT) + $taxitem['Value'] = -$taxitem['Value']; + $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, + $taxitem['purchasing_gl_code'], 0, 0, $taxitem['Value'], + $supp_trans->supplier_id, + "A general ledger transaction for the tax amount could not be added"); + } } } if ($trans_type == ST_SUPPCREDIT) @@ -217,6 +220,8 @@ function add_supp_invoice(&$supp_trans) // do not receive as ref because we chan $supp_trans->supplier_id, "The general ledger transaction for the control total could not be added"); + $to_allocate = ($invoice_items_total + $item_added_tax + $supp_trans->ov_discount); + foreach ($supp_trans->gl_codes as $entered_gl_code) { /*GL Items are straight forward - just do the debit postings to the GL accounts specified - @@ -301,9 +306,9 @@ function add_supp_invoice(&$supp_trans) // do not receive as ref because we chan $currency = get_supplier_currency($supp_trans->supplier_id); $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $iv_act, - $dim1, $dim2, $entered_grn->this_quantity_inv * $old_price, $supp_trans->supplier_id, "", $ex_rate); - $diff = get_diff_in_home_currency($supp_trans->supplier_id, $old_date, $date_, $old_price, - $line_taxfree); + $dim, $dim2, $entered_grn->this_quantity_inv * $old_price, $supp_trans->supplier_id, "", $ex_rate); + $diff = get_diff_in_home_currency($supp_trans->supplier_id, $old_date, $date_, $old_value, + $taxfree_line); $mat_cost = update_average_material_cost(null, $entered_grn->item_code, $diff/$entered_grn->this_quantity_inv, $entered_grn->this_quantity_inv, null, true); @@ -363,17 +368,18 @@ function add_supp_invoice(&$supp_trans) // do not receive as ref because we chan if ($invoice_alloc_balance > 0) { //the invoice is not already fully allocated - $trans = get_supp_trans($supp_trans->src_docs, ST_SUPPINVOICE); - $total = $trans['Total']; + $trans = get_supp_trans($invoice_id, ST_SUPPCREDIT); + $total = -$trans['Total']; $allocate_amount = ($invoice_alloc_balance > $total) ? $total : $invoice_alloc_balance; + /*Now insert the allocation record if > 0 */ if ($allocate_amount != 0) { - update_supp_trans_allocation(ST_SUPPINVOICE, $supp_trans->src_docs); - update_supp_trans_allocation(ST_SUPPCREDIT, $invoice_id); - add_supp_allocation($allocate_amount, ST_SUPPCREDIT, $invoice_id, ST_SUPPINVOICE, $supp_trans->src_docs, + add_supp_allocation($allocate_amount, ST_SUPPCREDIT, $invoice_id, ST_SUPPINVOICE, $invoice_no, $date_); + update_supp_trans_allocation(ST_SUPPINVOICE, $invoice_no); + update_supp_trans_allocation(ST_SUPPCREDIT, $invoice_id); exchange_variation(ST_SUPPCREDIT, $invoice_id, ST_SUPPINVOICE, $supp_trans->src_docs, $date_, $allocate_amount, PT_SUPPLIER); @@ -386,6 +392,7 @@ function add_supp_invoice(&$supp_trans) // do not receive as ref because we chan //_vd(get_payments_for($sales_order, ST_PURCHORDER)); //_vd(get_payments_for($invoice_id, ST_SUPPINVOICE)); //exit; + $supp_trans->trans_no = $invoice_id; hook_db_postwrite($supp_trans, $supp_trans->trans_type); commit_transaction(); @@ -603,16 +610,9 @@ function void_supp_invoice($type, $type_no) add_audit_trail(ST_JOURNAL, $id, $old_date); add_comments(ST_JOURNAL, $id, $old_date, $memo); - $Refs->save(ST_JOURNAL, $id, $ref); - } - } - /*$deliveries = get_deliveries_between($details_row["stock_id"], $old_date, $date_); - if ($deliveries[0] != 0) // have deliveries been done during the period? - { - update_stock_move_pid(ST_CUSTDELIVERY, $details_row["stock_id"], $old_date, $date_, 0, $mat_cost); + $Refs->save(ST_JOURNAL, $id, $ref); + } } - update_stock_move_pid(ST_SUPPRECEIVE, $details_row["stock_id"], $old_date, $old_date, $grn['supplier_id'], $mat_cost); - */ } } }