{
return false;
}
- $index = "<?php\nheader(\"Location: ../../index.php\");\n?>";
if ($new)
{
- $cdir = $comp_path.'/'.$id;
- @mkdir($cdir);
- save_to_file($cdir.'/'.'index.php', 0, $index);
-
- foreach($comp_subdirs as $dir)
- {
- @mkdir($cdir.'/'.$dir);
- save_to_file($cdir.'/'.$dir.'/'.'index.php', 0, $index);
- }
+ create_comp_dirs("$comp_path/$id", $comp_subdirs);
}
return true;
}
}
}
-
+function create_comp_dirs($comp_path, $comp_subdirs)
+{
+ $index = "<?php\nheader(\"Location: ../index.php\");\n?>";
+ $cdir = $comp_path;
+ @mkdir($cdir);
+ $f = @fopen("$cdir/index.php", "wb");
+ @fwrite($f, $index);
+ @fclose($f);
+
+ foreach($comp_subdirs as $dir)
+ {
+ @mkdir($cdir.'/'.$dir);
+ $f = @fopen("$cdir/$dir/index.php", "wb");
+ @fwrite($f, $index);
+ @fclose($f);
+ }
+}
?>
\ No newline at end of file
$from_gl_account = get_bank_gl_account($from_account);
$to_gl_account = get_bank_gl_account($to_account);
+ $total = 0;
// do the source account postings
- add_gl_trans($trans_type, $trans_no, $date_, $from_gl_account, 0, 0, "",
+ $total += add_gl_trans($trans_type, $trans_no, $date_, $from_gl_account, 0, 0, "",
-$amount, $currency);
add_bank_trans($trans_type, $trans_no, $from_account, $ref,
"Cannot insert a source bank transaction");
// do the destination account postings
- add_gl_trans($trans_type, $trans_no, $date_, $to_gl_account, 0, 0, "",
+ $total += add_gl_trans($trans_type, $trans_no, $date_, $to_gl_account, 0, 0, "",
$amount, $currency);
-
+ /*Post a balance post if $total != 0 */
+ add_gl_balance($trans_type, $trans_no, $date_, -$total);
+
add_bank_trans($trans_type, $trans_no, $to_account, $ref,
$date_, $amount, payment_person_types::misc(), "",
$currency, "Cannot insert a destination bank transaction");
-$total_amount, $currency, $person_type_id, $person_id);
add_bank_trans($trans_type, $trans_no, $from_account, $ref,
- $date_, -$total_amount, $person_type_id, $person_id,
- $currency, "Cannot insert a source bank transaction");
-
+ $date_, -$total_amount,
+ $person_type_id, $person_id,
+ $currency,
+ "Cannot insert a source bank transaction");
+ $total = 0;
foreach ($items->gl_items as $gl_item)
{
$is_bank_to = is_bank_account($gl_item->code_id);
}
// do the destination account postings
- add_gl_trans($trans_type, $trans_no, $date_, $gl_item->code_id,
+ $total += add_gl_trans($trans_type, $trans_no, $date_, $gl_item->code_id,
$gl_item->dimension_id, $gl_item->dimension2_id, $gl_item->reference,
$gl_item->amount, $currency, $person_type_id, $person_id);
}
}
+ // do the source account postings
+ add_gl_trans($trans_type, $trans_no, $date_, $bank_gl_account, 0, 0, "",
+ -$total, null, $person_type_id, $person_id);
+
add_comments($trans_type, $trans_no, $date_, $memo_);
references::save_last($ref, $trans_type);
if ($rate == 0)
$amount_in_home_currency = to_home_currency($amount, $currency, $date_);
else
- $amount_in_home_currency = round($amount * $rate, user_price_dec());
+ $amount_in_home_currency = round2($amount * $rate, user_price_dec());
}
else
- $amount_in_home_currency = $amount;
+ $amount_in_home_currency = round2($amount, user_price_dec());
if ($dimension == null || $dimension < 0)
$dimension = 0;
if ($dimension2 == null || $dimension2 < 0)
if ($err_msg == "")
$err_msg = "The GL transaction could not be inserted";
- return db_query($sql, $err_msg);
+ db_query($sql, $err_msg);
+ return $amount_in_home_currency;
}
//--------------------------------------------------------------------------------
return add_gl_trans($type, $trans_id, $date_, $account, $dimension, $dimension2, $memo_,
$amount, null, $person_type_id, $person_id, $err_msg);
else
- return null;
+ return 0;
}
+// Function for even out rounding problems
+function add_gl_balance($type, $trans_id, $date_, $amount, $person_type_id=null, $person_id=null)
+{
+ $amount = round2($amount, user_price_dec());
+ if ($amount != 0)
+ return add_gl_trans($type, $trans_id, $date_, get_company_pref('exchange_diff_act'), 0, 0, "",
+ $amount, null, $person_type_id, $person_id, "The balanced GL transaction could not be inserted");
+ else
+ return 0;
+}
+
//--------------------------------------------------------------------------------
function get_gl_transactions($from_date, $to_date, $trans_no=0,
function to_home_currency($amount, $currency_code, $date_)
{
$ex_rate = get_exchange_rate_to_home_currency($currency_code, $date_);
- return round($amount / $ex_rate, user_price_dec());
+ return round2($amount / $ex_rate, user_price_dec());
}
//----------------------------------------------------------------------------------
}
if (is_company_currency($curr))
return;
- $inv_amt = round($amount * $trans['rate'], user_price_dec());
- $pay_amt = round($amount * $pyt_trans['rate'], user_price_dec());
+ $inv_amt = round2($amount * $trans['rate'], user_price_dec());
+ $pay_amt = round2($amount * $pyt_trans['rate'], user_price_dec());
if ($inv_amt != $pay_amt)
{
$diff = $inv_amt - $pay_amt;
//--------------------------------------------------------------------------
+function round2($number, $decimals=0)
+{
+ $delta = ($number < 0 ? -.000001 : .000001);
+ return round($number+$delta, $decimals);
+}
+
function number_format2($number, $decimals=0)
{
global $thoseps, $decseps;
$tsep = $thoseps[$_SESSION["wa_current_user"]->prefs->tho_sep()];
$dsep = $decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()];
- return number_format($number, $decimals, $dsep, $tsep);
+ //return number_format($number, $decimals, $dsep, $tsep);
+ $delta = ($number < 0 ? -.000001 : .000001);
+ return number_format($number+$delta, $decimals, $dsep, $tsep);
}
//
// Current ui mode.
include_once($path_to_root . "/includes/session.inc");
-page(_("View Work Order Production"), true);
+$js = "";
+if ($use_popup_windows)
+ $js .= get_js_open_window(900, 500);
+page(_("View Work Order Production"), true, false, "", $js);
include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/manufacturing.inc");
{
$from = date2sql($from);
$to = date2sql($to);
- $sql = "SELECT SUM(-qty), AVG(standard_cost) FROM ".TB_PREF."stock_moves
+ $sql = "SELECT SUM(-qty), SUM(-qty*standard_cost) FROM ".TB_PREF."stock_moves
WHERE type=13 AND stock_id='$stock_id' AND
tran_date>='$from' AND tran_date<='$to' GROUP BY stock_id";
$result = db_query($sql, "The deliveries could not be updated");
return db_fetch_row($result);
}
+
+function get_diff_in_home_currency($supplier, $old_date, $date, $amount1, $amount2)
+{
+ $currency = get_supplier_currency($supplier);
+ $amount1 = to_home_currency($amount1, $currency, $old_date);
+ $amount2 = to_home_currency($amount2, $currency, $date);
+ return $amount2 - $amount1;
+}
//----------------------------------------------------------------------------------------
function add_supp_invoice($supp_trans) // do not receive as ref because we change locally
$supp_trans->reference, $supp_trans->supp_reference,
$invoice_items_total, $tax_total, $supp_trans->ov_discount);
+ $total = 0;
/* Now the control account */
$supplier_accounts = get_supplier_accounts($supp_trans->supplier_id);
- add_gl_trans_supplier($trans_type, $invoice_id, $date_, $supplier_accounts["payable_account"], 0, 0,
+ $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $supplier_accounts["payable_account"], 0, 0,
-($invoice_items_total + $tax_total + $supp_trans->ov_discount),
$supp_trans->supplier_id,
"The general ledger transaction for the control total could not be added");
between the std cost and the currency cost charged as converted at the ex rate of of the invoice is written off
to the purchase price variance account applicable to the item being invoiced.
*/
-
foreach ($supp_trans->gl_codes as $entered_gl_code)
{
$entered_gl_code->amount = -$entered_gl_code->amount;
$memo_ = $entered_gl_code->memo_;
- add_gl_trans_supplier($trans_type, $invoice_id, $date_, $entered_gl_code->gl_code,
+ $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $entered_gl_code->gl_code,
$entered_gl_code->gl_dim, $entered_gl_code->gl_dim2, $entered_gl_code->amount, $supp_trans->supplier_id);
add_supp_invoice_gl_item($trans_type, $invoice_id, $entered_gl_code->gl_code,
$line_tax = $entered_grn->full_charge_price($supp_trans->tax_group_id) - $line_taxfree;
$stock_gl_code = get_stock_gl_code($entered_grn->item_code);
- add_gl_trans_supplier($trans_type, $invoice_id, $date_, $stock_gl_code["inventory_account"],
+ $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $stock_gl_code["inventory_account"],
$stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
$entered_grn->this_quantity_inv * $line_taxfree, $supp_trans->supplier_id);
// -------------- if price changed since po received. 16 Aug 2008 Joe Hunt
$old_price = $old[2];
-
-
/*
If statement is removed. Should always check for deliveries nomatter if there has been a price change.
*/
//if ($old_price != $entered_grn->chg_price) // price-change, so update
//{
- $diff = $entered_grn->chg_price - $old_price;
- $old_date = sql2date($old[1]);
- // only update the diff (last parameter, adj_only is set to true).
- $mat_cost = update_average_material_cost($supp_trans->supplier_id, $entered_grn->item_code,
- $diff, $entered_grn->this_quantity_inv, $old_date, true);
- // added 2008-12-08 Joe Hunt. Update the purchase data table
- add_or_update_purchase_data($supp_trans->supplier_id, $entered_grn->item_code, $entered_grn->chg_price);
-
- // function just above this
- $deliveries = get_deliveries_between($entered_grn->item_code, $old_date, $date_);
- if ($deliveries[0] != 0) // have deliveries been done during the period?
+ //$diff = $entered_grn->chg_price - $old_price;
+ $old_date = sql2date($old[1]);
+ $diff = get_diff_in_home_currency($supp_trans->supplier_id, $old_date, $date_, $old_price,
+ $entered_grn->chg_price);
+ // always return due to change in currency.
+ $mat_cost = update_average_material_cost(null, $entered_grn->item_code,
+ $diff, $entered_grn->this_quantity_inv, $old_date, true);
+ // added 2008-12-08 Joe Hunt. Update the purchase data table
+ add_or_update_purchase_data($supp_trans->supplier_id, $entered_grn->item_code, $entered_grn->chg_price);
+ $deliveries = get_deliveries_between($entered_grn->item_code, $old_date, Today()); // extend the period, if invoice is before any deliveries.
+ if ($deliveries[0] != 0) // have deliveries been done during the period?
+ {
+ $deliveries[1] /= $deliveries[0];
+ $amt = ($mat_cost - $deliveries[1]) * $deliveries[0]; // $amt in home currency
+ if ($amt != 0.0)
{
-
- $amt = ($mat_cost - $deliveries[1]) * $deliveries[0]; // $amt in home currency
- if ($amt != 0.0)
- {
- add_gl_trans($trans_type, $invoice_id, $date_, $stock_gl_code["cogs_account"],
- $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], _("Cost diff."),
- $amt, null, null, null,
- "The general ledger transaction could not be added for the price variance of the inventory item");
- add_gl_trans($trans_type, $invoice_id, $date_, $stock_gl_code["inventory_account"],
- 0, 0, _("Cost diff."), -$amt, null, null, null,
- "The general ledger transaction could not be added for the price variance of the inventory item");
- }
- update_stock_move_pid(13, $entered_grn->item_code, $old_date, $date_, 0, $mat_cost);
- }
- update_stock_move_pid(25, $entered_grn->item_code, $old_date, $old_date, $supp_trans->supplier_id, $mat_cost);
- //}
+ add_gl_trans($trans_type, $invoice_id, $date_, $stock_gl_code["cogs_account"],
+ $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], _("Cost diff."),
+ $amt, null, null, null,
+ "The general ledger transaction could not be added for the price variance of the inventory item");
+ add_gl_trans($trans_type, $invoice_id, $date_, $stock_gl_code["inventory_account"],
+ 0, 0, _("Cost diff."), -$amt, null, null, null,
+ "The general ledger transaction could not be added for the price variance of the inventory item");
+ }
+ update_stock_move_pid(13, $entered_grn->item_code, $old_date, $date_, 0, $mat_cost);
+ }
+ update_stock_move_pid(25, $entered_grn->item_code, $old_date, $old_date, $supp_trans->supplier_id, $mat_cost);
+ //}
}
// ----------------------------------------------------------------------
add_supp_invoice_tax_item($trans_type, $invoice_id, $taxitem['tax_type_id'],
$taxitem['rate'], 0, $taxitem['Value']);
- add_gl_trans_supplier($trans_type, $invoice_id, $date_,
+ $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");
}
}
+
+ /*Post a balance post if $total != 0 */
+ add_gl_balance($trans_type, $invoice_id, $date_, -$total, payment_person_types::supplier(), $supp_trans->supplier_id);
+
add_comments($trans_type, $invoice_id, $date_, $supp_trans->Comments);
references::save_last($supp_trans->reference, $trans_type);
$old = update_supp_received_items_for_invoice($details_row["grn_item_id"],
$details_row["po_detail_item_id"], -$details_row["quantity"], $details_row["FullUnitPrice"]);
- $diff = $details_row["FullUnitPrice"] - $old[2];
+ //$diff = $details_row["FullUnitPrice"] - $old[2];
$old_date = sql2date($old[1]);
$batch = get_grn_batch_from_item($details_row["grn_item_id"]);
$grn = get_grn_batch($batch);
+ $diff = get_diff_in_home_currency($grn["supplier_id"], $old_date, $date_, $old[2],
+ $details_row["FullUnitPrice"]);
// Only adjust the avg for the diff
- $mat_cost = update_average_material_cost($grn["supplier_id"], $details_row["stock_id"],
- $diff, -$details_row["quantity"], $date_, true);
+ $mat_cost = update_average_material_cost(null, $details_row["stock_id"],
+ $diff, -$details_row["quantity"], $date_, true);
$deliveries = get_deliveries_between($details_row["stock_id"], $old_date, $date_);
if ($deliveries[0] != 0) // have deliveries been done during the period?
{
-
+ $deliveries[1] /= $deliveries[0];
$amt = ($mat_cost - $deliveries[1]) * $deliveries[0]; // $amt in home currency
if ($amt != 0.0)
{
}
else
{
- $supp_amount = $amount / $rate;
- $supp_discount = $discount / $rate;
+ $supp_amount = round($amount / $rate, user_price_dec());
+ $supp_discount = round($discount / $rate, user_price_dec());
}
// Now debit creditors account with payment + discount
+ $total = 0;
$supplier_accounts = get_supplier_accounts($supplier_id);
-
- add_gl_trans_supplier($trans_type, $payment_id, $date_, $supplier_accounts["payable_account"], 0, 0,
+ $total += add_gl_trans_supplier($trans_type, $payment_id, $date_, $supplier_accounts["payable_account"], 0, 0,
$supp_amount + $supp_discount, $supplier_id, "", $rate);
// Now credit discount received account with discounts
if ($supp_discount != 0)
{
- add_gl_trans_supplier($trans_type, $payment_id, $date_, $supplier_accounts["payment_discount_account"], 0, 0,
+ $total += add_gl_trans_supplier($trans_type, $payment_id, $date_, $supplier_accounts["payment_discount_account"], 0, 0,
-$supp_discount, $supplier_id, "", $rate);
}
if ($supp_amount != 0)
{
- add_gl_trans_supplier($trans_type, $payment_id, $date_, $bank_gl_account, 0, 0,
+ $total += add_gl_trans_supplier($trans_type, $payment_id, $date_, $bank_gl_account, 0, 0,
-$supp_amount, $supplier_id, "", $rate);
}
+ /*Post a balance post if $total != 0 */
+ add_gl_balance($trans_type, $payment_id, $date_, -$total, payment_person_types::supplier(), $supplier_id);
+
/*now enter the bank_trans entry */
add_bank_trans($trans_type, $payment_id, $bank_account, $ref,
$date_, -($amount), payment_person_types::supplier(),
function NewLine($l=1, $np=0)
{
$this->row -= ($l * $this->lineHeight);
- if ($np > 0 && $this->row < $this->bottomMargin + ($np * $this->lineHeight))
+ if ($this->row < $this->bottomMargin + ($np * $this->lineHeight))
$this->Header();
}
$SubTotal = 0;
while ($myrow2=db_fetch($result))
{
- $Net = round($sign * ((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
+ $Net = round2($sign * ((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
user_price_dec());
$SubTotal += $Net;
$DisplayPrice = number_format2($myrow2["unit_price"],$dec);
$SubTotal = 0;
while ($myrow2=db_fetch($result))
{
- $Net = round(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
+ $Net = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
user_price_dec());
$SubTotal += $Net;
$DisplayPrice = number_format2($myrow2["unit_price"],$dec);
$SubTotal = 0;
while ($myrow2=db_fetch($result))
{
- $Net = round(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
+ $Net = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
user_price_dec());
$SubTotal += $Net;
$DisplayPrice = number_format2($myrow2["unit_price"],$dec);
$myrow2['quantiry_ordered'] = round($myrow2['quantiry_ordered'] / $data['conversion_factor'], user_qty_dec());
}
}
- $Net = round(($myrow2["unit_price"] * $myrow2["quantity_ordered"]),
+ $Net = round2(($myrow2["unit_price"] * $myrow2["quantity_ordered"]),
user_price_dec());
$SubTotal += $Net;
$DisplayPrice = number_format2($myrow2["unit_price"],$dec);
".TB_PREF."stock_category.description AS cat_description,
".TB_PREF."stock_master.stock_id,
".TB_PREF."stock_master.description,
- ".TB_PREF."stock_moves.loc_code,
- SUM(".TB_PREF."stock_moves.qty) AS qty_on_hand
- FROM ".TB_PREF."stock_master,
- ".TB_PREF."stock_category,
- ".TB_PREF."stock_moves
- WHERE ".TB_PREF."stock_master.stock_id=".TB_PREF."stock_moves.stock_id
- AND ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
+ IF(".TB_PREF."stock_moves.stock_id IS NULL, '', ".TB_PREF."stock_moves.loc_code) AS loc_code,
+ SUM(IF(".TB_PREF."stock_moves.stock_id IS NULL,0,".TB_PREF."stock_moves.qty)) AS qty_on_hand
+ FROM (".TB_PREF."stock_master,
+ ".TB_PREF."stock_category)
+ LEFT JOIN ".TB_PREF."stock_moves ON
+ (".TB_PREF."stock_master.stock_id=".TB_PREF."stock_moves.stock_id OR ".TB_PREF."stock_master.stock_id IS NULL)
+ WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
AND (".TB_PREF."stock_master.mb_flag='B' OR ".TB_PREF."stock_master.mb_flag='M')";
if ($category != 0)
$sql .= " AND ".TB_PREF."stock_master.category_id = '$category'";
if ($location != 'all')
$sql .= " AND ".TB_PREF."stock_moves.loc_code = '$location'";
$sql .= " GROUP BY ".TB_PREF."stock_master.category_id,
- ".TB_PREF."stock_master.description,
".TB_PREF."stock_category.description,
- ".TB_PREF."stock_moves.stock_id,
- ".TB_PREF."stock_master.stock_id
+ ".TB_PREF."stock_master.stock_id,
+ ".TB_PREF."stock_master.description
ORDER BY ".TB_PREF."stock_master.category_id,
".TB_PREF."stock_master.stock_id";
$sql = "SELECT SUM(".TB_PREF."sales_order_details.quantity - ".TB_PREF."sales_order_details.qty_sent) AS qty_demand
FROM ".TB_PREF."sales_order_details,
".TB_PREF."sales_orders
- WHERE ".TB_PREF."sales_order_details.order_no=".TB_PREF."sales_orders.order_no AND
- ".TB_PREF."sales_orders.from_stk_loc ='$location' AND
- ".TB_PREF."sales_order_details.stk_code = '$stockid'";
+ WHERE ".TB_PREF."sales_order_details.order_no=".TB_PREF."sales_orders.order_no AND ";
+ if ($location != "")
+ $sql .= TB_PREF."sales_orders.from_stk_loc ='$location' AND ";
+ $sql .= TB_PREF."sales_order_details.stk_code = '$stockid'";
$TransResult = db_query($sql,"No transactions were returned");
$DemandRow = db_fetch($TransResult);
".TB_PREF."bom,
".TB_PREF."stock_master
WHERE ".TB_PREF."sales_order_details.stk_code=".TB_PREF."bom.parent AND
- ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no AND
- ".TB_PREF."sales_orders.from_stk_loc='$location' AND
- ".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent > 0 AND
+ ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no AND ";
+ if ($location != "")
+ $sql .= TB_PREF."sales_orders.from_stk_loc ='$location' AND ";
+ $sql .= TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent > 0 AND
".TB_PREF."bom.component='$stockid' AND
".TB_PREF."stock_master.stock_id=".TB_PREF."bom.parent AND
".TB_PREF."stock_master.mb_flag='A'";
FROM ".TB_PREF."purch_order_details,
".TB_PREF."purch_orders
WHERE ".TB_PREF."purch_order_details.order_no = ".TB_PREF."purch_orders.order_no
- AND ".TB_PREF."purch_order_details.item_code = '$stockid'
- AND ".TB_PREF."purch_orders.into_stock_location= '$location'";
+ AND ".TB_PREF."purch_order_details.item_code = '$stockid'";
+ if ($location != "")
+ $sql .= " AND ".TB_PREF."purch_orders.into_stock_location= '$location'";
$TransResult = db_query($sql,"No transactions were returned");
$DemandRow = db_fetch($TransResult);
$catt = $trans['cat_description'];
$rep->NewLine();
}
-
- $custqty = getCustQty($trans['stock_id'], $trans['loc_code']);
- $custqty += getCustAsmQty($trans['stock_id'], $trans['loc_code']);
- $suppqty = getSuppQty($trans['stock_id'], $trans['loc_code']);
+ if ($location == 'all')
+ $loc_code = "";
+ else
+ $loc_code = $trans['loc_code'];
+ $custqty = getCustQty($trans['stock_id'], $loc_code);
+ $custqty += getCustAsmQty($trans['stock_id'], $loc_code);
+ $suppqty = getSuppQty($trans['stock_id'], $loc_code);
$period = getPeriods($trans['stock_id'], $trans['loc_code']);
$rep->NewLine();
$dec = get_qty_dec($trans['stock_id']);
".TB_PREF."stock_category.description AS cat_description,
".TB_PREF."stock_master.stock_id,
".TB_PREF."stock_master.description,
- ".TB_PREF."stock_moves.loc_code,
- SUM(".TB_PREF."stock_moves.qty) AS QtyOnHand
- FROM ".TB_PREF."stock_master,
- ".TB_PREF."stock_category,
- ".TB_PREF."stock_moves
- WHERE ".TB_PREF."stock_master.stock_id=".TB_PREF."stock_moves.stock_id
- AND ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
+ IF(".TB_PREF."stock_moves.stock_id IS NULL, '', ".TB_PREF."stock_moves.loc_code) AS loc_code,
+ SUM(IF(".TB_PREF."stock_moves.stock_id IS NULL,0,".TB_PREF."stock_moves.qty)) AS QtyOnHand
+ FROM (".TB_PREF."stock_master,
+ ".TB_PREF."stock_category)
+ LEFT JOIN ".TB_PREF."stock_moves ON
+ (".TB_PREF."stock_master.stock_id=".TB_PREF."stock_moves.stock_id OR ".TB_PREF."stock_master.stock_id IS NULL)
+ WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
AND (".TB_PREF."stock_master.mb_flag='B' OR ".TB_PREF."stock_master.mb_flag='M')";
if ($category != 0)
$sql .= " AND ".TB_PREF."stock_master.category_id = '$category'";
$sql = "SELECT SUM(".TB_PREF."sales_order_details.quantity - ".TB_PREF."sales_order_details.qty_sent) AS QtyDemand
FROM ".TB_PREF."sales_order_details,
".TB_PREF."sales_orders
- WHERE ".TB_PREF."sales_order_details.order_no=".TB_PREF."sales_orders.order_no AND
- ".TB_PREF."sales_orders.from_stk_loc ='$location' AND
- ".TB_PREF."sales_order_details.stk_code = '$stockid'";
+ WHERE ".TB_PREF."sales_order_details.order_no=".TB_PREF."sales_orders.order_no AND ";
+ if ($location != "")
+ $sql .= TB_PREF."sales_orders.from_stk_loc ='$location' AND ";
+ $sql .= TB_PREF."sales_order_details.stk_code = '$stockid'";
$TransResult = db_query($sql,"No transactions were returned");
$DemandRow = db_fetch($TransResult);
".TB_PREF."bom,
".TB_PREF."stock_master
WHERE ".TB_PREF."sales_order_details.stk_code=".TB_PREF."bom.parent AND
- ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no AND
- ".TB_PREF."sales_orders.from_stk_loc='$location' AND
- ".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent > 0 AND
+ ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no AND ";
+ if ($location != "")
+ $sql .= TB_PREF."sales_orders.from_stk_loc ='$location' AND ";
+ $sql .= TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent > 0 AND
".TB_PREF."bom.component='$stockid' AND
".TB_PREF."stock_master.stock_id=".TB_PREF."bom.parent AND
".TB_PREF."stock_master.mb_flag='A'";
$catt = $trans['cat_description'];
$rep->NewLine();
}
- $demandqty = getDemandQty($trans['stock_id'], $trans['loc_code']);
- $demandqty += getDemandAsmQty($trans['stock_id'], $trans['loc_code']);
+ if ($location == 'all')
+ $loc_code = "";
+ else
+ $loc_code = $trans['loc_code'];
+ $demandqty = getDemandQty($trans['stock_id'], $loc_code);
+ $demandqty += getDemandAsmQty($trans['stock_id'], $loc_code);
$rep->NewLine();
$dec = get_qty_dec($trans['stock_id']);
$rep->TextCol(0, 1, $trans['stock_id']);
table_header($th);
$k = 0;
$has_marked = false;
-$show_qoh = true;
foreach ($_SESSION['Items']->line_items as $line=>$ln_itm) {
if ($ln_itm->quantity==$ln_itm->qty_done) {
continue; //this line is fully delivered
}
// if it's a non-stock item (eg. service) don't show qoh
+ $show_qoh = true;
if (sys_prefs::allow_negative_stock() || !has_stock_holding($ln_itm->mb_flag) ||
$ln_itm->qty_dispatched == 0) {
$show_qoh = false;
function remove_from_cart($line_no)
{
- unset($this->line_items[$line_no]);
+ array_splice($this->line_items, $line_no, 1);
}
function clear_items()
void_gl_trans(12, $trans_no, true);
void_cust_allocations(12, $trans_no, $date_);
}
-
+ $total = 0;
/* Bank account entry first */
- add_gl_trans_customer(12, $payment_no, $date_,
+ $total += add_gl_trans_customer(12, $payment_no, $date_,
$bank_gl_account, 0, 0, $amount, $customer_id,
"Cannot insert a GL transaction for the bank account debit", $rate);
if (($discount + $amount) != 0) {
/* Now Credit Debtors account with receipts + discounts */
- add_gl_trans_customer(12, $payment_no, $date_,
+ $total += add_gl_trans_customer(12, $payment_no, $date_,
$debtors_account, 0, 0, -($discount + $amount), $customer_id,
"Cannot insert a GL transaction for the debtors account credit", $rate);
}
-
if ($discount != 0) {
/* Now Debit discount account with discounts allowed*/
- add_gl_trans_customer(12, $payment_no, $date_,
+ $total += add_gl_trans_customer(12, $payment_no, $date_,
$discount_account, 0, 0, $discount, $customer_id,
"Cannot insert a GL transaction for the payment discount debit", $rate);
}
+ /*Post a balance post if $total != 0 */
+ add_gl_balance(12, $payment_no, $date_, -$total, payment_person_types::customer(), $customer_id);
+
/*now enter the bank_trans entry */
add_bank_trans(12, $payment_no, $bank_account, $ref,
$date_, $amount, payment_person_types::customer(), $customer_id,
}
}
-
+ $total = 0;
foreach ($credit_note->line_items as $credit_line) {
if ($credit_invoice && $credit_line->qty_dispatched!=$credit_line->qty_old ) {
add_credit_movements_item($credit_note, $credit_line,
$credit_type, $line_taxfree_price+$line_tax, $credit_invoice);
- add_gl_trans_credit_costs($credit_note, $credit_line, $credit_no,
+ $total += add_gl_trans_credit_costs($credit_note, $credit_line, $credit_no,
$credit_date, $credit_type, $write_off_acc, $branch_data);
} /*end of credit_line loop */
if (($credit_note_total + $credit_note->freight_cost) != 0) {
- add_gl_trans_customer(11, $credit_no, $credit_date, $branch_data["receivables_account"], 0, 0,
+ $total += add_gl_trans_customer(11, $credit_no, $credit_date, $branch_data["receivables_account"], 0, 0,
-($credit_note_total + $credit_note->freight_cost + $items_added_tax + $freight_added_tax),
$credit_note->customer_id,
"The total debtor GL posting for the credit note could not be inserted");
}
if ($credit_note->freight_cost !=0) {
- add_gl_trans_customer(11, $credit_no, $credit_date, $company_data["freight_act"], 0, 0,
+ $total += add_gl_trans_customer(11, $credit_no, $credit_date, $company_data["freight_act"], 0, 0,
$credit_note->get_tax_free_shipping(), $credit_note->customer_id,
"The freight GL posting for this credit note could not be inserted");
}
add_customer_trans_tax_detail_item(11, $credit_no, $taxitem['tax_type_id'],
$taxitem['rate'], $credit_note->tax_included, $taxitem['Value']);
- add_gl_trans_customer(11, $credit_no, $credit_date, $taxitem['sales_gl_code'], 0, 0,
+ $total += add_gl_trans_customer(11, $credit_no, $credit_date, $taxitem['sales_gl_code'], 0, 0,
$taxitem['Value'], $credit_note->customer_id,
"A tax GL posting for this credit note could not be inserted");
}
}
+ /*Post a balance post if $total != 0 */
+ add_gl_balance(11, $credit_no, $credit_date, -$total, payment_person_types::customer(), $credit_note->customer_id);
+
add_comments(11, $credit_no, $credit_date, $credit_note->Comments);
if ($trans_no == 0) {
$dim2 = ($order->dimension2_id != $customer['dimension2_id'] ? $order->dimension2_id :
($customer['dimension2_id'] != 0 ? $customer["dimension2_id"] : $stock_gl_codes["dimension2_id"]));
+ $total = 0;
/* insert gl_trans to credit stock and debit cost of sales at standard cost*/
$standard_cost = get_standard_cost($order_line->stock_id);
if ($standard_cost != 0) {
/*first the cost of sales entry*/
- add_gl_trans_std_cost(11, $credit_no, $date_, $stock_gl_codes["cogs_account"],
+ $total += add_gl_trans_std_cost(11, $credit_no, $date_, $stock_gl_codes["cogs_account"],
$dim, $dim2, "", -($standard_cost * $order_line->qty_dispatched),
payment_person_types::customer(), $order->customer_id,
"The cost of sales GL posting could not be inserted");
$stock_entry_account = $stock_gl_code["inventory_account"];
}
- add_gl_trans_std_cost(11, $credit_no, $date_, $stock_entry_account, 0, 0,
+ $total += add_gl_trans_std_cost(11, $credit_no, $date_, $stock_entry_account, 0, 0,
"", ($standard_cost * $order_line->qty_dispatched),
payment_person_types::customer(), $order->customer_id,
"The stock side (or write off) of the cost of sales GL posting could not be inserted");
$sales_account = $branch_data['sales_account'];
else
$sales_account = $stock_gl_codes['sales_account'];
- add_gl_trans_customer(11, $credit_no, $date_, $sales_account, $dim, $dim2,
+ $total += add_gl_trans_customer(11, $credit_no, $date_, $sales_account, $dim, $dim2,
($line_taxfree_price * $order_line->qty_dispatched), $order->customer_id,
"The credit note GL posting could not be inserted");
if ($order_line->discount_percent != 0) {
- add_gl_trans_customer(11, $credit_no, $date_, $branch_data["sales_discount_account"],
+ $total += add_gl_trans_customer(11, $credit_no, $date_, $branch_data["sales_discount_account"],
$dim, $dim2, -($line_taxfree_price * $order_line->qty_dispatched * $order_line->discount_percent),
$order->customer_id,
"The credit note discount GL posting could not be inserted");
} /*end of if discount !=0 */
} /*if line_price!=0 */
+ return $total;
}
?>
\ No newline at end of file
void_cust_allocations(10, $invoice_no); // ?
void_customer_trans_tax_details(10, $invoice_no);
}
-
+ $total = 0;
foreach ($invoice->line_items as $invoice_line) {
$line_taxfree_price = get_tax_free_price_for_item($invoice_line->stock_id,
($customer['dimension_id'] != 0 ? $customer["dimension_id"] : $stock_gl_code["dimension_id"]));
$dim2 = ($invoice->dimension2_id != $customer['dimension2_id'] ? $invoice->dimension2_id :
($customer['dimension2_id'] != 0 ? $customer["dimension2_id"] : $stock_gl_code["dimension2_id"]));
- add_gl_trans_customer(10, $invoice_no, $date_, $sales_account, $dim, $dim2,
+ $total += add_gl_trans_customer(10, $invoice_no, $date_, $sales_account, $dim, $dim2,
(-$line_taxfree_price * $invoice_line->qty_dispatched),
$invoice->customer_id, "The sales price GL posting could not be inserted");
if ($invoice_line->discount_percent != 0) {
- add_gl_trans_customer(10, $invoice_no, $date_,
+ $total += add_gl_trans_customer(10, $invoice_no, $date_,
$branch_data["sales_discount_account"], $dim, $dim2,
($line_taxfree_price * $invoice_line->qty_dispatched * $invoice_line->discount_percent),
$invoice->customer_id, "The sales discount GL posting could not be inserted");
} /*quantity dispatched is more than 0 */
} /*end of delivery_line loop */
- /*Post debtors transaction to GL debit debtors, credit freight re-charged and credit sales */
if (($items_total + $charge_shipping) != 0) {
- add_gl_trans_customer(10, $invoice_no, $date_, $branch_data["receivables_account"], 0, 0,
+ $total += add_gl_trans_customer(10, $invoice_no, $date_, $branch_data["receivables_account"], 0, 0,
($items_total + $charge_shipping + $items_added_tax + $freight_added_tax),
$invoice->customer_id, "The total debtor GL posting could not be inserted");
}
+
if ($charge_shipping != 0) {
- add_gl_trans_customer(10, $invoice_no, $date_, $company_data["freight_act"], 0, 0,
+ $total += add_gl_trans_customer(10, $invoice_no, $date_, $company_data["freight_act"], 0, 0,
-$invoice->get_tax_free_shipping(), $invoice->customer_id,
"The freight GL posting could not be inserted");
}
add_customer_trans_tax_detail_item(10, $invoice_no, $taxitem['tax_type_id'],
$taxitem['rate'], $invoice->tax_included, $taxitem['Value']);
- add_gl_trans_customer(10, $invoice_no, $date_, $taxitem['sales_gl_code'], 0, 0,
+ $total += add_gl_trans_customer(10, $invoice_no, $date_, $taxitem['sales_gl_code'], 0, 0,
(-$taxitem['Value']), $invoice->customer_id,
"A tax GL posting could not be inserted");
}
}
+ /*Post a balance post if $total != 0 */
+ add_gl_balance(10, $invoice_no, $date_, -$total, payment_person_types::customer(), $invoice->customer_id);
+
add_comments(10, $invoice_no, $date_, $invoice->Comments);
if ($trans_no == 0) {
if ($factor == 0) return false; // auto price calculations off
$base_id = get_base_sales_type();
- $home_curr = get_company_currency();
+ if ($base_id <= 0) return 0; // auto price calculations off
+
+ $home_curr = get_company_currency();
// get all prices which we can use to guess the price.
// alternative is make up to 2 additional sql queries
date_row(_("Date:"), 'OrderDate', '', null, 0, 0, 0, null, true);
if (isset($_POST['_OrderDate_changed'])) {
- $change_prices = 1;
+ if (!is_company_currency($order->customer_currency)
+ && (get_base_sales_type()>0)) {
+ $change_prices = 1;
+ }
$Ajax->activate('currency');
}
// 2008-11-12 Joe Hunt added dimensions
date_row($date_text, 'OrderDate',
_('Date of order receive'), null, 0, 0, 0, null, true);
if (isset($_POST['_OrderDate_changed'])) {
- $change_prices = 1;
+ if (!is_company_currency($order->customer_currency)
+ && (get_base_sales_type()>0)) {
+ $change_prices = 1;
+ }
$Ajax->activate('currency');
if ($order->trans_type == 10) {
$_POST['delivery_date'] = get_invoice_duedate(get_post('customer_id'), get_post('OrderDate'));
alt_table_row_color($k);
- $value = round(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
+ $value = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
user_price_dec());
$sub_total += $value;
if($myrow2['quantity']==0) continue;
alt_table_row_color($k);
- $value = round(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
+ $value = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
user_price_dec());
$sub_total += $value;
if($myrow2["quantity"]==0) continue;
alt_table_row_color($k);
- $value = round(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
+ $value = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
user_price_dec());
$sub_total += $value;
foreach ($_SESSION['Items']->line_items as $stock_item) {
- $line_total = round($stock_item->quantity * $stock_item->price * (1 - $stock_item->discount_percent),
+ $line_total = round2($stock_item->quantity * $stock_item->price * (1 - $stock_item->discount_percent),
user_price_dec());
alt_table_row_color($k);
foreach ($item_taxes as $item_tax)
{
$index = $item_tax['tax_type_id'];
- if($tax_included==1)
- $ret_tax_array[$index]['Value'] += round($prices[$i] * $item_tax['rate']
- / ($item_tax['rate'] + 100), user_price_dec());
+ if($tax_included==1) // 2008-11-26 Joe Hunt Taxes are stored without roundings
+ //$ret_tax_array[$index]['Value'] += round($prices[$i] * $item_tax['rate']
+ // / ($item_tax['rate'] + 100), user_price_dec());
+ $ret_tax_array[$index]['Value'] += ($prices[$i] * $item_tax['rate'] / ($item_tax['rate'] + 100));
else
- $ret_tax_array[$index]['Value'] +=
- round($prices[$i] * $item_tax['rate'] / 100, user_price_dec());
+ //$ret_tax_array[$index]['Value'] +=
+ // round($prices[$i] * $item_tax['rate'] / 100, user_price_dec());
+ $ret_tax_array[$index]['Value'] += ($prices[$i] * $item_tax['rate'] / 100);
}
}
}
{
$index = $item_tax['tax_type_id'];
if(isset($ret_tax_array[$index])) {
- if($tax_included==1)
- $ret_tax_array[$index]['Value'] += round($shipping_cost * $item_tax['rate']
- / ($item_tax['rate'] + 100), user_price_dec());
+ if($tax_included==1) // 2008-11-26 Joe Hunt Taxes are stored without roundings
+ //$ret_tax_array[$index]['Value'] += round($shipping_cost * $item_tax['rate']
+ // / ($item_tax['rate'] + 100), user_price_dec());
+ $ret_tax_array[$index]['Value'] += ($shipping_cost * $item_tax['rate'] / ($item_tax['rate'] + 100));
else
- $ret_tax_array[$index]['Value'] +=
- round($shipping_cost * $item_tax['rate'] / 100, user_price_dec());
+ //$ret_tax_array[$index]['Value'] +=
+ // round($shipping_cost * $item_tax['rate'] / 100, user_price_dec());
+ $ret_tax_array[$index]['Value'] += ($shipping_cost * $item_tax['rate'] / 100);
}
}
}
<li>Upload all the new files.
</li>
<li>Restore the files mentioned in #1. Be <strong>careful</strong> with
- <strong>config.db</strong>. Look into variances. There might be new variables in
+ <strong>config.php</strong>. Look into variances. There might be new variables in
the new version. It might be easier to <em>manually change your former values in
the new file</em>.
</li>
do this, before entering FrontAccounting!
Enter the database user and the password and choose the alter.sql
script. Do the same for the alter2.sql script. If you have
-already updated release 2.0 Beta, you can just run the alter2.sql script.<br />You must also manuelly ensure that you have write permission to the new folder /company/0.<br /></strong><strong>There are no database changes during a major and minor release. Like from 2.0 to 2.0.1 - 2.0.5 .</strong></li>
+already updated release 2.0 Beta, you can just run the alter2.sql script.<br />You must also manuelly ensure that you have write permission to the new folder /company .<br /></strong><strong>There are no database changes during a major and minor release. Like from 2.0 to 2.0.1 - 2.0.5 .</strong></li>
</ul>
<p> </p>
$image = $path_to_root."/themes/default/images/logo_frontaccounting.png";
$title = "Update All Company Databases";
+$comp_subdirs = array('images', 'pdf_files', 'backup','js_cache');
+
function get_js_png_fix()
{
$js = "<script type=\"text/javascript\">\n"
if (isset($_POST["submit"]))
{
- if (!isset($_FILES['uploadfile']['tmp_name']) || !is_uploaded_file($_FILES['uploadfile']['tmp_name']))
+ $perms_ok = is_writable($path_to_root.'/company') && is_writable($path_to_root.'/company/0');
+ $checkdirs = $comp_subdirs;
+ foreach ($checkdirs as $dir) {
+ $perms_ok &= is_writable($path_to_root.'/company/0/'.$dir);
+ }
+
+ if (!$perms_ok) {
+ display_error("'System 'company' directory or any of its subdirectories
+ is not writable.<br> Change webserver access permissions to those
+ directories.");
+ } elseif (!isset($_FILES['uploadfile']['tmp_name']) || !is_uploaded_file($_FILES['uploadfile']['tmp_name']))
{
display_error("You must select an SQL script for update");;
}
display_notification("Database has been updated for company: "
. $id . " " . $conn['name']);
}
+ $cdir = "$path_to_root/company/$id";
+ if (!file_exists($cdir))
+ {
+ create_comp_dirs($cdir, $comp_subdirs);
+ }
}
}
}
$_POST['passwd'] = "";
if (!isset($_POST['user']))
$_POST['user'] = "";
-
+
echo "<form enctype='multipart/form-data' method='post' action='".$_SERVER['PHP_SELF']."'>\n";
echo "<table align='center' width='50%' cellpadding=3 border=1 bordercolor='#cccccc' style='border-collapse: collapse'>\n";