From: Mithy Date: Sun, 29 Nov 2015 13:43:49 +0000 (+0100) Subject: Added fixed assets module X-Git-Tag: v2.4.2~19^2~120 X-Git-Url: https://delta.frontaccounting.com/gitweb/?p=fa-stable.git;a=commitdiff_plain;h=fd069bba86276f15311ff6ab10b22d4a06a55513 Added fixed assets module --- diff --git a/admin/gl_setup.php b/admin/gl_setup.php index 3836493b..415fca0e 100644 --- a/admin/gl_setup.php +++ b/admin/gl_setup.php @@ -72,8 +72,8 @@ if (isset($_POST['submit']) && can_process()) update_company_prefs( get_post( array( 'retained_earnings_act', 'profit_loss_year_act', 'debtors_act', 'pyt_discount_act', 'creditors_act', 'freight_act', 'deferred_income_act', 'exchange_diff_act', 'bank_charge_act', 'default_sales_act', 'default_sales_discount_act', - 'default_prompt_payment_act', 'default_inventory_act', 'default_cogs_act', - 'default_adj_act', 'default_inv_sales_act', 'default_assembly_act', 'legal_text', + 'default_prompt_payment_act', 'default_inventory_act', 'default_cogs_act', 'depreciation_period', + 'default_loss_on_asset_disposal_act', 'default_adj_act', 'default_inv_sales_act', 'default_assembly_act', 'legal_text', 'past_due_days', 'default_workorder_required', 'default_dim_required', 'default_receival_required', 'default_delivery_required', 'default_quote_valid_days', 'grn_clearing_act', 'tax_algorithm', 'no_zero_lines_amount', 'show_po_item_codes', 'accounts_alpha', 'loc_notification', 'print_invoice_no', @@ -141,6 +141,8 @@ $_POST['loc_notification'] = $myrow['loc_notification']; $_POST['print_invoice_no'] = $myrow['print_invoice_no']; $_POST['allow_negative_prices'] = $myrow['allow_negative_prices']; $_POST['print_item_images_on_quote'] = $myrow['print_item_images_on_quote']; +$_POST['default_loss_on_asset_disposal_act'] = $myrow['default_loss_on_asset_disposal_act']; +$_POST['depreciation_period'] = $myrow['depreciation_period']; //--------------- @@ -249,6 +251,14 @@ gl_all_accounts_list_row(_("Item Assembly Costs Account:"), 'default_assembly_ac //---------------- +table_section_title(_("Fixed Assets Defaults")); + +gl_all_accounts_list_row(_("Loss On Asset Disposal Account:"), 'default_loss_on_asset_disposal_act', $_POST['default_loss_on_asset_disposal_act']); + +array_selector_row (_("Depreciation Period:"), 'depreciation_period', $_POST['depreciation_period'], array(FA_MONTHLY => _("Monthly"), FA_YEARLY => _("Yearly"))); + +//---------------- + table_section_title(_("Manufacturing Defaults")); text_row(_("Work Order Required By After:"), 'default_workorder_required', $_POST['default_workorder_required'], 6, 6, '', "", _("days")); diff --git a/applications/fixed_assets.php b/applications/fixed_assets.php new file mode 100644 index 00000000..35aa150a --- /dev/null +++ b/applications/fixed_assets.php @@ -0,0 +1,56 @@ +. +***********************************************************************/ +class assets_app extends application +{ + function assets_app() + { + $this->application("assets", _($this->help_context = "&Fixed Assets")); + + $this->add_module(_("Transactions")); + $this->add_lapp_function(0, _("FA &Purchase"), + "purchasing/po_entry_items.php?NewInvoice=Yes&FixedAsset=1", 'SA_SUPPLIERINVOICE', MENU_TRANSACTION); + $this->add_lapp_function(0, _("FA Location &Transfers"), + "inventory/transfers.php?NewTransfer=1&FixedAsset=1", 'SA_ASSETTRANSFER', MENU_TRANSACTION); + $this->add_lapp_function(0, _("FA &Disposal"), + "inventory/adjustments.php?NewAdjustment=1&FixedAsset=1", 'SA_ASSETDISPOSAL', MENU_TRANSACTION); + $this->add_lapp_function(0, _("FA &Sale"), + "sales/sales_order_entry.php?NewInvoice=0&FixedAsset=1", 'SA_SALESINVOICE', MENU_TRANSACTION); + $this->add_rapp_function(0, _("Process &Depreciation"), + "fixed_assets/process_depreciation.php", 'SA_DEPRECIATION', MENU_MAINTENANCE); + // TODO: needs work + //$this->add_rapp_function(0, _("FA &Revaluation"), + // "inventory/cost_update.php?FixedAsset=1", 'SA_STANDARDCOST', MENU_MAINTENANCE); + + $this->add_module(_("Inquiries and Reports")); + $this->add_lapp_function(1, _("FA Item In&quiry"), + "fixed_assets/inquiry/stock_inquiry.php?", 'SA_ASSETSANALYTIC', MENU_INQUIRY); + + $this->add_rapp_function(1, _("FA Item &Movements"), + "inventory/inquiry/stock_movements.php?FixedAsset=1", 'SA_ASSETSTRANSVIEW', MENU_INQUIRY); + + $this->add_module(_("Maintenance")); + + $this->add_lapp_function(2, _("Fixed &Assets"), + "inventory/manage/items.php?FixedAsset=1", 'SA_ASSET', MENU_ENTRY); + $this->add_rapp_function(2, _("FA &Locations"), + "inventory/manage/locations.php?FixedAsset=1", 'SA_INVENTORYLOCATION', MENU_MAINTENANCE); + $this->add_rapp_function(2, _("FA Item &Categories"), + "inventory/manage/item_categories.php?FixedAsset=1", 'SA_ASSETCATEGORY', MENU_MAINTENANCE); + $this->add_rapp_function(2, _("FA Cl&asses"), + "fixed_assets/fixed_asset_classes.php", 'SA_ASSETCLASS', MENU_MAINTENANCE); + + $this->add_extensions(); + } +} + + +?> diff --git a/fixed_assets/fixed_asset_classes.php b/fixed_assets/fixed_asset_classes.php new file mode 100644 index 00000000..87c3218d --- /dev/null +++ b/fixed_assets/fixed_asset_classes.php @@ -0,0 +1,153 @@ +. +***********************************************************************/ +$page_security = 'SA_ASSETCLASS'; +$path_to_root = ".."; +include($path_to_root . "/includes/session.inc"); + +include_once($path_to_root . "/includes/ui.inc"); + +include_once($path_to_root . "/fixed_assets/includes/fixed_assets_db.inc"); +include_once($path_to_root . "/fixed_assets/includes/fa_classes_db.inc"); + +page(_($help_context = "Fixed asset classes")); + +simple_page_mode(true); + +if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') +{ + + //initialise no input errors assumed initially before we test + $input_error = 0; + + /* actions to take once the user has clicked the submit button + ie the page has called itself with some user input */ + + if ($input_error != 1) + { + if ($selected_id != -1) + { + update_fixed_asset_class($selected_id, $_POST['parent_id'], $_POST['description'], $_POST['long_description'], + $_POST['depreciation_method'], $_POST['depreciation_rate'], $_POST['depreciation_period']); + display_notification(_('Selected fixed asset class has been updated')); + } + else + { + add_fixed_asset_class($_POST['fa_class_id'], $_POST['parent_id'], $_POST['description'], $_POST['long_description'], + $_POST['depreciation_method'], $_POST['depreciation_rate'], $_POST['depreciation_period']); + display_notification(_('New fixed asset class has been added')); + } + + $Mode = 'RESET'; + } +} + +function can_delete($selected_id) +{ + if (key_in_foreign_table($selected_id, 'stock_master', 'fa_class_id')) + { + display_error(_("Cannot delete this class because it is used by some fixed asset items.")); + return false; + } + return true; +} + +//---------------------------------------------------------------------------------- + +if ($Mode == 'Delete') +{ + + if (can_delete($selected_id)) + { + delete_fixed_asset_class($selected_id); + display_notification(_('Selected fixed asset class has been deleted')); + } //end if Delete Location + $Mode = 'RESET'; +} + +if ($Mode == 'RESET') +{ + $selected_id = -1; + unset($_POST); +} + +$result = get_fixed_asset_classes(); + +start_form(); +start_table(TABLESTYLE); +$th = array(_("Fixed asset class"), _("Description"), _("Depreciation method"), _("Depreciation rate"), _("Depreciation period"), "", ""); +inactive_control_column($th); +table_header($th); +$k = 0; //row colour counter +while ($myrow = db_fetch($result)) +{ + alt_table_row_color($k); + + label_cell($myrow["fa_class_id"]); + label_cell($myrow["description"]); + label_cell($depreciation_methods[$myrow["depreciation_method"]]); + label_cell($myrow["depreciation_rate"].'%'); + label_cell($myrow["depreciation_period"].' years'); + inactive_control_cell($myrow["fa_class_id"], $myrow["inactive"], 'stock_fa_classes', 'fa_class_id'); + edit_button_cell("Edit".$myrow["fa_class_id"], _("Edit")); + delete_button_cell("Delete".$myrow["fa_class_id"], _("Delete")); + end_row(); +} +inactive_control_row($th); +end_table(1); + +echo '
'; + +start_form(true); + +start_table(TABLESTYLE2); + +if ($selected_id != -1) +{ + if ($Mode == 'Edit') { + $myrow = get_fixed_asset_class($selected_id); + + $_POST['fa_class_id'] = $myrow["fa_class_id"]; + $_POST['parent_id'] = $myrow["parent_id"]; + $_POST['description'] = $myrow["description"]; + $_POST['long_description'] = $myrow["long_description"]; + $_POST['depreciation_method'] = $myrow["depreciation_method"]; + $_POST['depreciation_rate'] = $myrow["depreciation_rate"]; + $_POST['depreciation_period'] = $myrow["depreciation_period"]; + } + hidden("selected_id", $selected_id); + hidden("fa_class_id"); + hidden('parent_id'); + label_row(_("Parent class:"), $_POST['parent_id']); + label_row(_("Fixed asset class:"), $_POST['fa_class_id']); +} +else +{ + text_row(_("Parent class:"), 'parent_id', null, 3, 3); + text_row(_("Fixed asset class:"), 'fa_class_id', null, 3, 3); +} + +text_row(_("Description:"), 'description', null, 42, 200); +textarea_row(_('Long description:'), 'long_description', null, 42, 3); +array_selector_row(_("Depreciation Method").":", "depreciation_method", null, $depreciation_methods, array('select_submit'=> true)); +small_amount_row(_("Depreciation Rate").':', 'depreciation_rate', null, null, '%', user_percent_dec()); +text_row_ex(_("Depreciation Period").':', 'depreciation_period', 3, 3, '', null, null, _("years")); + +//text_row(_("Parent id:"), 'parent_id', null, 3, 3); + +end_table(1); + +//if ($selected_id != -1) +submit_add_or_update_center($selected_id == -1, '', 'both'); + +end_form(); + +end_page(); diff --git a/fixed_assets/includes/depreciation.inc b/fixed_assets/includes/depreciation.inc new file mode 100644 index 00000000..dda99f96 --- /dev/null +++ b/fixed_assets/includes/depreciation.inc @@ -0,0 +1,117 @@ +. + ***********************************************************************/ + +function next_depreciation_date($depreciation_date) { + + $start = strtotime($depreciation_date); + + $y = date('Y', $start); + $m = date('n', $start) + 1; + + if ($m > 12) { + $m = 1; + $y++; + } + + return strtotime("$y-$m-1"); +} + +function depreciation_months($depreciation_start) { + + // assume that depreciation start is the same fiscal year + //$start = strtotime($depreciation_start); + //$end = strtotime($year['end']); + + $start = next_depreciation_date($depreciation_start); + + return 12 - date('n', $start) + 1; + + //$d1 = date('j', $start); // day of the month + //$d2 = date('t', $start); // number of days in month + + //if ($d2 > $d1) + //$months++; +} + +function months_between_dates($start, $end) { + $start = strtotime($start); + $end = strtotime($end); + + $y1 = date('Y', $start); + $m1 = date('n', $start); + + $y2 = date('Y', $end); + $m2 = date('n', $end); + + return 12 * ($y2 - $y1) + $m2 - $m1; +} + +function compute_gl_rows_for_depreciation($item, $no_months, $period) { + $rows = array(); + + $year = get_current_fiscalyear(); + $y = date('Y', strtotime($year['end'])); + + switch ($item['depreciation_method']) { + case 'D': + $value = $item['material_cost'] * $item['depreciation_rate'] / 100 / 12; + break; + + case 'S': + // depreciation_rate is the period here. + $done_months = months_between_dates($item['depreciation_start'], $item['depreciation_date']); + $remaining_months = $item['depreciation_rate'] * 12 - $done_months; + $value = $item['material_cost'] / $remaining_months; + break; + + case 'O': + $value = $item['material_cost']; + break; + } + + $next = next_depreciation_date($item['depreciation_date']); + $m = date('n', $next); + + $total = 0; + $cnt = 0; + for ($i=$m; $i < $m + $no_months; $i++) { + $date = sql2date(date("$y-$i-t", strtotime("$y-$i-1"))); + + $total += $value; + + if (FA_YEARLY == $period) { + // yearly + if ($i == $m + $no_months - 1) + $rows[] = array('date' => $date, 'value' => $total); + /*else + $rows[] = array('date' => $date, 'value' => 0); + */ + } + else { + // monthly + $rows[] = array('date' => $date, 'value' => $value); + } + + $cnt++; + + if ($item['depreciation_method'] == 'S') { + if ($cnt >= $remaining_months) + $value = 0; + } + elseif ($item['depreciation_method'] == 'O') { + // depreciate only in the first month + $value = 0; + } + } + + return $rows; +} diff --git a/fixed_assets/includes/fa_classes_db.inc b/fixed_assets/includes/fa_classes_db.inc new file mode 100644 index 00000000..3c5b68cf --- /dev/null +++ b/fixed_assets/includes/fa_classes_db.inc @@ -0,0 +1,53 @@ +. +***********************************************************************/ + +function get_fixed_asset_classes() +{ + $sql="SELECT * FROM ".TB_PREF."stock_fa_class"; + + $result = db_query($sql,"fixed asset classes could not be retrieved"); + + return $result; +} + +function update_fixed_asset_class($fa_class_id, $parent_id, $description, $long_description, $depreciation_method, $depreciation_rate, $depreciation_period) +{ + $sql = "UPDATE ".TB_PREF."stock_fa_class SET + parent_id=".db_escape($parent_id).", + description=".db_escape($description).", + long_description=".db_escape($long_description).", + depreciation_method=".db_escape($depreciation_method).", + depreciation_rate=".db_escape($depreciation_rate).", + depreciation_period=".db_escape($depreciation_period)." + WHERE fa_class_id=".db_escape($fa_class_id); + + db_query($sql, "The fixed asset class could not be updated"); +} + +function add_fixed_asset_class($fa_class_id, $parent_id, $description, $long_description, $depreciation_method, $depreciation_rate, $depreciation_period) +{ + $sql = "INSERT INTO ".TB_PREF."stock_fa_class (fa_class_id, parent_id, description, long_description, + depreciation_method, depreciation_rate, depreciation_period) VALUES (" + .db_escape($fa_class_id).", ".db_escape($parent_id).", " + .db_escape($description).", ".db_escape($long_description).", " + .db_escape($depreciation_method).", ".db_escape($depreciation_rate).", " + .db_escape($depreciation_period).")"; + + db_query($sql, "The fixed asset class could not be added"); +} + +function delete_fixed_asset_class($fa_class_id) +{ + $sql = "DELETE FROM ".TB_PREF."stock_fa_class WHERE fa_class_id=".db_escape($fa_class_id); + + db_query($sql, "The fixed asset class could not be deleted"); +} diff --git a/fixed_assets/includes/fixed_assets_db.inc b/fixed_assets/includes/fixed_assets_db.inc new file mode 100644 index 00000000..3a588874 --- /dev/null +++ b/fixed_assets/includes/fixed_assets_db.inc @@ -0,0 +1,198 @@ +. +***********************************************************************/ + +function process_fixed_asset_depreciation($stock_id, $gl_rows, $refline, $memo_) +{ + global $Refs; + + $row = get_item($stock_id); + $old_cost = $row['material_cost']; + + begin_transaction(); + + $date_ = Today(); + if (!is_date_in_fiscalyear($date_)) + $date_ = end_fiscalyear(); + + $stock_gl_code = get_stock_gl_code($stock_id); + + $cart = new items_cart(ST_JOURNAL); + $cart->tran_date = $cart->doc_date = $cart->event_date = $date_; + $cart->tran_date = end_fiscalyear(); + $cart->reference = $Refs->get_next(ST_JOURNAL, $refline, $cart->tran_date, $date_); + + $value_of_change = 0; + foreach ($gl_rows as $row) { + $value_of_change += round($row['value'], 2); + + $cart->add_gl_item($stock_gl_code["adjustment_account"], + $stock_gl_code["dimension_id"], $stock_gl_code["dimension2_id"], -$row['value'], + '', null, null, $row['date']); + $cart->add_gl_item($stock_gl_code["cogs_account"], 0, 0, $row['value'], + '', null, null, $row['date']); + } + + $new_cost = $old_cost - $value_of_change; + + if (empty($memo_)) + $cart->memo_ = sprintf(_("Fixed asset has been deprecated by the value of %s"), + number_format2($value_of_change, 2)); + else + $cart->memo_ = $memo_; + + $trans_no = write_journal_entries($cart); + + $sql = "UPDATE ".TB_PREF."stock_master SET + depreciation_date='".date2sql($cart->tran_date)."', + material_cost=".db_escape($new_cost).", + last_cost=".db_escape($old_cost)." + WHERE stock_id=".db_escape($stock_id); + db_query($sql,"The depreciation start date could not be updated"); + + $update_no = -1; + add_audit_trail(ST_JOURNAL, $update_no, $date_); + commit_transaction(); + + return $trans_no; +} + +//-------------------------------------------------------------------------------------------------- + +function get_fixed_asset_move($stock_id, $tran_type) { + + $sql = "SELECT * FROM ".TB_PREF."stock_moves + WHERE stock_id=".db_escape($stock_id)." + AND type=".db_escape($tran_type); + + $result = db_query($sql, "cannot retrieve fixed asset move"); + + if (db_num_rows($result) == 0) + return false; + + $row = db_fetch_assoc($result); + return $row; +} + +function get_fixed_asset_disposal($stock_id) { + + $sql = "SELECT * FROM ".TB_PREF."stock_moves + WHERE stock_id=".db_escape($stock_id)." + AND (type=".ST_INVADJUST." OR type=".ST_CUSTDELIVERY.")"; + + $result = db_query($sql, "cannot retrieve fixed asset move"); + + if (db_num_rows($result) == 0) + return false; + + $row = db_fetch_assoc($result); + return $row; +} + +function get_fixed_asset_purchase($stock_id) { + + $sql = "SELECT * + FROM ".TB_PREF."stock_master m, " + .TB_PREF."supp_invoice_items i, " + .TB_PREF."supp_trans t + WHERE m.stock_id=".db_escape($stock_id)." + AND i.supp_trans_no=t.trans_no + AND m.stock_id=i.stock_id"; + + $result = db_query($sql, "cannot retrieve fixed asset move"); + + if (db_num_rows($result) == 0) + return false; + + $row = db_fetch_assoc($result); + return $row; +} + +//-------------------------------------------------------------------------------------------------- + +function get_initial_price($stock_id) { + $row = get_fixed_asset_move($stock_id, ST_SUPPRECEIVE); + return $row['price']; +} + +//-------------------------------------------------------------------------------------------------- + +function get_fixed_asset_class($id) +{ + $sql="SELECT * FROM ".TB_PREF."stock_fa_class WHERE fa_class_id=".db_escape($id); + + $result = db_query($sql,"a fixed asset class could not be retrieved"); + + return db_fetch($result); +} + +//-------------------------------------------------------------------------------------------------- + +function get_sql_for_fixed_assets($show_inactive = false) +{ + $sql = "SELECT s.stock_id, c.description, s.units, s.long_description, + s.depreciation_rate, s.depreciation_method, s.inactive, rcv.tran_date as purchase_date, rcv.trans_no as purchase_no, + adj.tran_date as disposal_date, adj.type as disposal_type, adj.trans_no as disposal_no + FROM ".TB_PREF."stock_master s" + ." LEFT JOIN ".TB_PREF."stock_moves rcv ON rcv.stock_id=s.stock_id AND rcv.type=".ST_SUPPRECEIVE + ." LEFT JOIN ".TB_PREF."stock_moves adj ON adj.stock_id=s.stock_id AND adj.type IN(".ST_INVADJUST.",".ST_CUSTDELIVERY.")" + ." LEFT JOIN ".TB_PREF."stock_fa_class c ON s.fa_class_id=c.fa_class_id" + ." WHERE s.mb_flag='F'"; + + if (!$show_inactive) + $sql .= " AND !s.inactive AND !ISNULL(rcv.tran_date) AND ISNULL(adj.tran_date)"; + + return $sql; +} + +//-------------------------------------------------------------------------------------------------- + +//function get_sql_for_fa_journal_inquiry($stock_id) +//{ +// +// $sql = "SELECT IF(ISNULL(a.gl_seq),0,a.gl_seq) as gl_seq, +// gl.tran_date, +// gl.type as trans_type, +// gl.type_no as trans_no, +// IFNULL(max(supp.supp_name), max(cust.name)) as name, +// refs.reference, +// SUM(IF(gl.amount>0, gl.amount,0)) as amount, +// com.memo_, +// IF(ISNULL(u.user_id),'',u.user_id) as user_id"; +// +// $sql.= " FROM ".TB_PREF."gl_trans as gl +// LEFT JOIN ".TB_PREF."audit_trail as a ON +// (gl.type=a.type AND gl.type_no=a.trans_no) +// LEFT JOIN ".TB_PREF."comments as com ON +// (gl.type=com.type AND gl.type_no=com.id) +// LEFT JOIN ".TB_PREF."refs as refs ON +// (gl.type=refs.type AND gl.type_no=refs.id) +// LEFT JOIN ".TB_PREF."users as u ON +// a.user=u.id +// LEFT JOIN ".TB_PREF."debtor_trans dt ON dt.type=gl.type AND gl.type_no=dt.trans_no +// LEFT JOIN ".TB_PREF."debtors_master cust ON gl.person_type_id=2 AND gl.person_id=cust.debtor_no +// LEFT JOIN ".TB_PREF."supp_trans st ON st.type=gl.type AND gl.type_no=st.trans_no +// LEFT JOIN ".TB_PREF."suppliers supp ON gl.person_type_id=3 AND gl.person_id=supp.supplier_id +// WHERE gl.amount!=0 +// AND NOT ISNULL(a.gl_seq)"; +// +//// if (!$alsoclosed) { +//// $sql .= " AND gl_seq=0"; +//// } +//// else +//// $sql .= " AND NOT ISNULL(a.gl_seq)"; +// +// $sql .= " GROUP BY tran_date, gl_seq, trans_type, trans_no"; +// +// return $sql; +//} + +//-------------------------------------------------------------------------------------------------- diff --git a/fixed_assets/inquiry/stock_inquiry.php b/fixed_assets/inquiry/stock_inquiry.php new file mode 100644 index 00000000..24c7c9be --- /dev/null +++ b/fixed_assets/inquiry/stock_inquiry.php @@ -0,0 +1,147 @@ +. +***********************************************************************/ +$page_security = 'SA_ASSETSANALYTIC'; +$path_to_root = "../.."; +include($path_to_root . "/includes/db_pager.inc"); +include($path_to_root . "/includes/session.inc"); + +include($path_to_root . "/purchasing/includes/purchasing_ui.inc"); +include($path_to_root . "/reporting/includes/reporting.inc"); +include($path_to_root . "/fixed_assets/includes/fixed_assets_db.inc"); + +$js = ""; +if ($SysPrefs->use_popup_windows) + $js .= get_js_open_window(900, 500); +if (user_use_date_picker()) + $js .= get_js_date_picker(); +page(_($help_context = "FA Item Inquiry"), false, false, "", $js); + +if (isset($_GET['location'])) +{ + $_POST['location'] = $_GET['location']; +} + +//------------------------------------------------------------------------------------------------ + +start_form(); + +start_table(TABLESTYLE_NOBORDER); +start_row(); +//locations_list_cells(_("From Location:"), 'location', null, false, false, true); +check_cells( _("Show inactive:"), 'show_inactive', null); +submit_cells('RefreshInquiry', _("Search"),'',_('Refresh Inquiry'), 'default'); +end_row(); + +end_table(); + +//------------------------------------------------------------------------------------------------ + +if(get_post('RefreshInquiry')) +{ + $Ajax->activate('totals_tbl'); +} + +function gl_view($row) +{ + $row = get_fixed_asset_move($row['stock_id'], ST_JOURNAL); + + //if ($row === false) + //return ""; + + //return get_journal_trans_view_str(ST_JOURNAL, $row["trans_no"], sql2date($row["tran_date"])); + return get_gl_view_str(ST_JOURNAL, $row["trans_no"]); +} + +function fa_link($row) +{ + $url = "inventory/manage/items.php?FixedAsset=1&stock_id=".$row['stock_id']; + + return viewer_link($row['stock_id'], $url); +} + +function depr_method_title($row) { + global $depreciation_methods; + return $depreciation_methods[$row['depreciation_method']]; +} + +function depr_rate_title($row) { + if ($row['depreciation_method'] == 'S') + return $row['depreciation_rate'].' years'; + else + return $row['depreciation_rate'].'%'; +} + +function status_title($row) { + + if ($row['inactive'] || ($row['disposal_date'] !== NULL)) + return _("Disposed"); // disposed or saled + elseif ($row['purchase_date'] === NULL) + return _("Purchasable"); // not yet purchased + else + return _("Active"); // purchased + +} + +function purchase_link($row) +{ + + if ($row['purchase_date'] === null) + return ""; + + return get_supplier_trans_view_str(ST_SUPPRECEIVE, $row["purchase_no"], sql2date($row["purchase_date"])); +} + +function disposal_link($row) +{ + switch ($row['disposal_type']) { + case ST_INVADJUST: + return get_inventory_trans_view_str(ST_INVADJUST, $row["disposal_no"], sql2date($row["disposal_date"])); + case ST_CUSTDELIVERY: + return get_customer_trans_view_str(ST_CUSTDELIVERY, $row["disposal_no"], sql2date($row["disposal_date"])); + default: + return ""; + } +} + +//------------------------------------------------------------------------------------------------ + +$sql = get_sql_for_fixed_assets(get_post('show_inactive')); + +$cols = array( + //_("Type") => array('fun'=>'systype_name', 'ord'=>''), + //_("#") => array('fun'=>'trans_view', 'ord'=>''), + _("Item") => array('fun' => 'fa_link'), + _("FA Class"), + _("Units of Measure") => array('align' => 'center'), + _("Long description"), + _("Depreciation Rate or Lifecycle") => array('fun' => 'depr_rate_title'), + _("Depreciation Method") => array('fun' => 'depr_method_title'), + _("Status") => array('fun' => 'status_title'), + _("Purchase") => array('fun' => 'purchase_link'), + _("Liquidation or Sale") => array('align' => 'center', 'fun' => 'disposal_link'), + //array('insert'=>true, 'fun'=>'gl_view'), + //array('insert'=>true, 'fun'=>'rm_link'), + //array('insert'=>true, 'fun'=>'edit_link'), + //array('insert'=>true, 'fun'=>'prt_link'), + ); + +//------------------------------------------------------------------------------------------------ + +/*show a table of the transactions returned by the sql */ +$table =& new_db_pager('fixed_assets_tbl', $sql, $cols); + +$table->width = "85%"; + +display_db_pager($table); + +end_form(); +end_page(); diff --git a/fixed_assets/process_depreciation.php b/fixed_assets/process_depreciation.php new file mode 100644 index 00000000..14accf61 --- /dev/null +++ b/fixed_assets/process_depreciation.php @@ -0,0 +1,194 @@ +. + ***********************************************************************/ +$page_security = 'SA_DEPRECIATION'; +$path_to_root = ".."; + +include_once($path_to_root . "/includes/session.inc"); + +include_once($path_to_root . "/includes/date_functions.inc"); +include_once($path_to_root . "/admin/db/fiscalyears_db.inc"); +include_once($path_to_root . "/includes/ui.inc"); +include_once($path_to_root . "/includes/data_checks.inc"); +include_once($path_to_root . "/includes/ui/items_cart.inc"); + +include_once($path_to_root . "/fixed_assets/includes/depreciation.inc"); +include_once($path_to_root . "/fixed_assets/includes/fixed_assets_db.inc"); + +$js = ""; +if (user_use_date_picker()) + $js .= get_js_date_picker(); + +page(_($help_context = "Process Depreciation"), false, false, "", $js); + +//--------------------------------------------------------------------------------------------- +function check_data() +{ + $myrow = get_item($_POST['stock_id']); + + if ($_POST['months'] > depreciation_months($myrow['depreciation_date'])) { + display_error(_("The number of months is greater than the timespan between the depreciation start and the end of the fiscal year.")); + set_focus('months'); + return false; + } + + return true; +} + +//--------------------------------------------------------------------------------------------- + +function handle_submit() +{ + if (!check_data()) + return; + + $item = get_item($_POST['stock_id']); + + $period = get_company_pref('depreciation_period'); + $gl_rows = compute_gl_rows_for_depreciation($item, $_POST['months'], $period); + + $trans_no = process_fixed_asset_depreciation($_POST['stock_id'], $gl_rows, $_POST['refline'], $_POST['memo_']); + + meta_forward($_SERVER['PHP_SELF'], "AddedID=".$trans_no); +} + +//--------------------------------------------------------------------------------------------- + +if (get_post('process')) + handle_submit(); + +//--------------------------------------------------------------------------------------------- + +if (isset($_GET['AddedID'])) +{ + $trans_no = $_GET['AddedID']; + $trans_type = ST_JOURNAL; + + display_notification(_("The fixed asset has been depreciated for this year")); + + display_note(get_gl_view_str($trans_type, $trans_no, _("View the GL &Postings for this Depreciation")), 1, 0); + + hyperlink_no_params($_SERVER['PHP_SELF'], _("Depreciate &Another Fixed Asset")); + + display_footer_exit(); +} + +//-------------------------------------------------------------------------------------- + +check_db_has_depreciable_fixed_assets(_("There are no fixed assets that could be depreciated.")); + +//--------------------------------------------------------------------------------------------- + +function show_gl_rows() { + + $item = get_item($_POST['stock_id']); + + hidden('stock_id'); + hidden('months'); + hidden('refline'); + hidden('memo_'); + + start_table(TABLESTYLE, "width=40%"); + $th = array(_("Item"), _('Date'), _('Account'), _('Debit'), _("Credit")); + + table_header($th); + $k = 0; //row colour counter + + $period = get_company_pref('depreciation_period'); + $gl_rows = compute_gl_rows_for_depreciation($item, $_POST['months'], $period); + + foreach($gl_rows as $myrow) + { + alt_table_row_color($k); + label_cell($item['stock_id']); + label_cell($myrow["date"]); + label_cell($item['cogs_account'].' '.get_gl_account_name($item["cogs_account"])); + amount_cell($myrow["value"]); + label_cell(""); + end_row(); + + alt_table_row_color($k); + label_cell($item['stock_id']); + label_cell($myrow["date"]); + label_cell($item["adjustment_account"].' '.get_gl_account_name($item["adjustment_account"])); + label_cell(""); + amount_cell($myrow["value"]); + end_row(); + } + + end_table(1); + + submit_center('process', _("Process Depreciation"), true, false); +} + +function show_gl_controls() { + global $Ajax; + + check_db_has_stock_items('There are no active fixed asset defined in the system.'); + + start_table(TABLESTYLE_NOBORDER); + start_row(); + stock_depreciable_fa_list_cells(_("Select an item:"), 'stock_id', null, + false, true); + end_row(); + end_table(); + + $myrow = get_item($_POST['stock_id']); + + if (list_updated('stock_id') || !isset($_POST['months'])) { + //$_POST['depreciation_start'] = sql2date($myrow['depreciation_start']); + $_POST['months'] = depreciation_months($myrow['depreciation_date']); + unset($_POST['memo_']); + } + + $Ajax->activate('depreciation_date'); + $Ajax->activate('months'); + $Ajax->activate('memo_'); + + start_table(TABLESTYLE2); + + if (!isset($_POST['date'])) + $_POST['date'] = Today(); + + $start = next_depreciation_date($myrow['depreciation_date']); + $start_text = _(date('F', $start)).' '.date('Y', $start); + + //date_row(_("Starting from month").":", 'depreciation_start', '', null, 0, 0, 0, null, true); + label_row(_("Starting from month").":", $start_text, null, null, 0, 'depreciation_date'); + $period = get_company_pref('depreciation_period'); + if ($period != FA_YEARLY) { + text_row(_("Period").":", 'months', null, 4, 3, null, null, _("months")); + } + else { + label_row(_("Period").":", '1 year'); + hidden ('months'); + } + refline_list_row(_("Reference line:"), 'refline', ST_JOURNAL, null, false, true); + textarea_row(_("Memo:"), 'memo_', null, 40,4); + + end_table(1); + + submit_center_first('show', _("Show GL Rows"), true, false); + submit_center_last('process', _("Process Depreciation"), true, false); +} + +//--------------------------------------------------------------------------------------------- + +start_form(); + +if (isset($_POST['show']) && check_data()) + show_gl_rows(); +else + show_gl_controls(); + +end_form(); + +end_page(); diff --git a/frontaccounting.php b/frontaccounting.php index 2e81867b..56418165 100644 --- a/frontaccounting.php +++ b/frontaccounting.php @@ -15,6 +15,7 @@ if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_ include_once($path_to_root . '/applications/customers.php'); include_once($path_to_root . '/applications/suppliers.php'); include_once($path_to_root . '/applications/inventory.php'); + include_once($path_to_root . '/applications/fixed_assets.php'); include_once($path_to_root . '/applications/manufacturing.php'); include_once($path_to_root . '/applications/dimensions.php'); include_once($path_to_root . '/applications/generalledger.php'); @@ -77,6 +78,7 @@ if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_ $this->add_application(new customers_app()); $this->add_application(new suppliers_app()); $this->add_application(new inventory_app()); + $this->add_application(new assets_app()); $this->add_application(new manufacturing_app()); $this->add_application(new dimensions_app()); $this->add_application(new general_ledger_app()); diff --git a/includes/access_levels.inc b/includes/access_levels.inc index aee33a6d..4e3bb1ab 100644 --- a/includes/access_levels.inc +++ b/includes/access_levels.inc @@ -40,6 +40,10 @@ define('SS_ITEMS_C',31<<8); define('SS_ITEMS', 32<<8); define('SS_ITEMS_A',33<<8); +define('SS_ASSETS_C',36<<8); +define('SS_ASSETS', 37<<8); +define('SS_ASSETS_A',38<<8); + define('SS_MANUF_C',41<<8); define('SS_MANUF', 42<<8); define('SS_MANUF_A',43<<8); @@ -65,6 +69,9 @@ $security_sections = array( SS_ITEMS_C => _("Inventory configuration"), SS_ITEMS => _("Inventory operations"), SS_ITEMS_A => _("Inventory analytics"), + SS_ASSETS_C => _("Fixed Assets configuration"), + SS_ASSETS => _("Fixed Assets operations"), + SS_ASSETS_A => _("Fixed Assets analytics"), SS_MANUF_C => _("Manufacturing configuration"), SS_MANUF => _("Manufacturing transactions"), SS_MANUF_A => _("Manufacturing analytics"), @@ -187,6 +194,20 @@ $security_areas =array( 'SA_ITEMSANALYTIC' => array(SS_ITEMS_A|2, _("Items analytical reports and inquiries")), 'SA_ITEMSVALREP' => array(SS_ITEMS_A|3, _("Inventory valuation report")), +// +// Fixed Assets +// + 'SA_ASSET' => array(SS_ASSETS_C|1, _("Fixed Asset items add/edit")), + 'SA_ASSETCATEGORY' => array(SS_ASSETS_C|2, _("Fixed Asset categories")), + 'SA_ASSETCLASS' => array(SS_ASSETS_C|4, _("Fixed Asset classes")), + + 'SA_ASSETSTRANSVIEW' => array(SS_ASSETS|1, _("Fixed Asset transactions view")), + 'SA_ASSETTRANSFER' => array(SS_ASSETS|2, _("Fixed Asset location transfers")), + 'SA_ASSETDISPOSAL' => array(SS_ASSETS|3, _("Fixed Asset disposals")), + 'SA_DEPRECIATION' => array(SS_ASSETS|4, _("Depreciation")), + + 'SA_ASSETSANALYTIC' => array(SS_ASSETS_A|1, _("Fixed Asset analytical reports and inquiries")), + // // Manufacturing module // diff --git a/includes/data_checks.inc b/includes/data_checks.inc index 8449b5dd..7cc5586d 100644 --- a/includes/data_checks.inc +++ b/includes/data_checks.inc @@ -37,21 +37,21 @@ function check_db_has_currencies($msg) { display_error($msg, true); end_page(); - exit; - } + exit; + } } function db_has_currency_rates($currency, $date_, $msg=false) { $date = date2sql($date_); - + if (is_company_currency($currency)) return 1; $ret = check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."exchange_rates WHERE curr_code = '$currency' && date_ <= '$date'"); if ($ret == 0 && $msg) display_error(sprintf(_("Cannot retrieve exchange rate for currency %s as of %s. Please add exchange rate manually on Exchange Rates page."), $currency, $date_), true); - return $ret; + return $ret; } function db_has_sales_types() @@ -250,7 +250,8 @@ function check_db_has_suppliers($msg) function db_has_stock_items() { - return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master"); + + return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE mb_flag!='F'"); } function check_db_has_stock_items($msg) @@ -328,9 +329,128 @@ function check_db_has_costable_items($msg) } } +function check_db_has_fixed_asset_classes($msg) +{ + global $path_to_root; + if (!db_has_fixed_asset_classes()) + { + display_error($msg, true); + end_page(); + exit; + } +} + +function db_has_fixed_asset_classes() +{ + return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_fa_class"); +} + +function db_has_depreciable_fixed_assets() +{ + $year = get_current_fiscalyear(); + $y = date('Y', strtotime($year['end'])); + + return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master + WHERE mb_flag='F' + AND material_cost > 0 + AND stock_id IN ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 ) + AND stock_id NOT IN ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 ) + AND depreciation_date < '".$y."-12-01' + AND depreciation_date >= '".($y-1)."-12-01'"); +} + +function check_db_has_depreciable_fixed_assets($msg) +{ + global $path_to_root; + + if (!db_has_depreciable_fixed_assets()) + { + display_error($msg, true); + end_page(); + exit; + } +} + +function db_has_fixed_assets() +{ + return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE mb_flag='F'"); +} + +function check_db_has_fixed_assets($msg) +{ + global $path_to_root; + + if (!db_has_fixed_assets()) + { + display_error($msg, true); + end_page(); + exit; + } +} + +function db_has_purchasable_fixed_assets() +{ + return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master + WHERE mb_flag='F' + AND !inactive + AND stock_id NOT IN + ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )"); +} + +function check_db_has_purchasable_fixed_assets($msg) +{ + global $path_to_root; + + if (!db_has_purchasable_fixed_assets()) + { + display_error($msg, true); + end_page(); + exit; + } +} + +function db_has_disposable_fixed_assets() +{ + return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master + WHERE mb_flag='F' + AND !inactive + AND stock_id IN + ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 ) + AND stock_id NOT IN + ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )"); +} + +function check_db_has_disposable_fixed_assets($msg) +{ + global $path_to_root; + + if (!db_has_disposable_fixed_assets()) + { + display_error($msg, true); + end_page(); + exit; + } +} + function db_has_stock_categories() { - return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_category"); + return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_category WHERE dflt_mb_flag!='F'"); +} + +function check_db_has_fixed_asset_categories($msg) +{ + global $path_to_root; + if (!db_has_fixed_asset_categories()) + { + display_error($msg, true); + end_page(); + exit; + } +} + +function db_has_fixed_asset_categories() +{ + return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_category WHERE dflt_mb_flag='F'"); } function check_db_has_stock_categories($msg) @@ -340,8 +460,8 @@ function check_db_has_stock_categories($msg) { display_error($msg, true); end_page(); - exit; - } + exit; + } } function db_has_workcentres() @@ -362,7 +482,7 @@ function check_db_has_workcentres($msg) function db_has_locations() { - return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."locations"); + return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."locations WHERE fixed_asset=0"); } function check_db_has_locations($msg) diff --git a/includes/db/class.reflines_db.inc b/includes/db/class.reflines_db.inc index 344a18bf..22c472dc 100644 --- a/includes/db/class.reflines_db.inc +++ b/includes/db/class.reflines_db.inc @@ -139,6 +139,7 @@ class reflines_db extends data_set { function count($type, $all=false) { $sql = "SELECT count(*) FROM ".TB_PREF."reflines WHERE trans_type=".db_escape($type); + if (!$all) $sql .= " AND !inactive"; $result = db_query($sql, "cannot retreive refline count for transaction type $type"); @@ -149,7 +150,7 @@ class reflines_db extends data_set { /* Recognize refline by reference prefix */ - function find_refline_id($reference, $type, $fallback = true) + function find_refline_id($reference, $type, $fallback=true) { $sql = "SELECT * FROM ".TB_PREF."reflines WHERE trans_type=".db_escape($type) ." AND CHAR_LENGTH(`prefix`) AND LEFT('$reference', CHAR_LENGTH(`prefix`)) = `prefix`"; @@ -167,7 +168,7 @@ class reflines_db extends data_set { function save_next($type, $reference, $line=null) { $sql = "UPDATE ".TB_PREF."reflines SET pattern=SUBSTRING(" . db_escape(trim($reference)) .", LENGTH(`prefix`)+1)" - . " WHERE trans_type = ".db_escape($type) . " AND "; + . " WHERE trans_type = ".db_escape($type)." AND "; if (isset($line)) $sql .= "`id`=".db_escape($line); diff --git a/includes/db/inventory_db.inc b/includes/db/inventory_db.inc index 3909e7c7..c01e4eb4 100644 --- a/includes/db/inventory_db.inc +++ b/includes/db/inventory_db.inc @@ -388,7 +388,7 @@ function update_stock_move($type, $trans_no, $stock_id, $cost) function get_stock_moves($type, $type_no) { - $sql = "SELECT move.*, item.description, item.units, stock.location_name, + $sql = "SELECT move.*, item.description, item.mb_flag, item.units, stock.location_name, item.material_cost + item.labour_cost + item.overhead_cost AS FixedStandardCost FROM ".TB_PREF."stock_moves move," .TB_PREF."locations stock," diff --git a/includes/inventory.inc b/includes/inventory.inc index 84638a8e..b90f6f31 100644 --- a/includes/inventory.inc +++ b/includes/inventory.inc @@ -27,6 +27,11 @@ function is_service($mb_flag) return ($mb_flag == 'D'); } +function is_fixed_asset($mb_flag) +{ + return ($mb_flag == 'F'); +} + function has_stock_holding($mb_flag) { return is_purchased($mb_flag) || is_manufactured($mb_flag); diff --git a/includes/sysnames.inc b/includes/sysnames.inc index efb700ba..70c78fef 100644 --- a/includes/sysnames.inc +++ b/includes/sysnames.inc @@ -40,7 +40,12 @@ $systypes_array = array ( ST_SALESORDER => _("Sales Order"), ST_SALESQUOTE => _("Sales Quotation"), ST_COSTUPDATE => _("Cost Update"), - ST_DIMENSION => _("Dimension") + ST_DIMENSION => _("Dimension"), + ); + +$fa_systypes_array = array ( + ST_INVADJUST => _("FA Disposal"), + ST_COSTUPDATE => _("FA Revaluation"), ); $type_shortcuts = array( @@ -151,6 +156,14 @@ $quick_entry_types = array( QE_SUPPINV => _("Supplier Invoice/Credit") ); +//---------------------------------------------------------------------------------- +// depreciation methods +$depreciation_methods = array( + 'D' => _("Declining balance"), + 'S' => _("Straight line"), + 'O' => _("One-time"), +); + //---------------------------------------------------------------------------------- // Types of stock items $stock_types = array( diff --git a/includes/types.inc b/includes/types.inc index f07b83b3..7242f86c 100644 --- a/includes/types.inc +++ b/includes/types.inc @@ -36,6 +36,11 @@ define('ST_WORKORDER', 26); define('ST_MANUISSUE', 28); define('ST_MANURECEIVE', 29); +// +// Depreciation period types +// +define('FA_MONTHLY', 0); +define('FA_YEARLY', 1); define('ST_SALESORDER', 30); define('ST_SALESQUOTE', 32); diff --git a/includes/ui/class.reflines_crud.inc b/includes/ui/class.reflines_crud.inc index 5871e489..70403f62 100644 --- a/includes/ui/class.reflines_crud.inc +++ b/includes/ui/class.reflines_crud.inc @@ -84,6 +84,7 @@ class fa_reflines extends simple_crud_view { $fresh = $selected_id == $this->_none || !$this->data_set->is_used(get_post($this->name.'prefix'), get_post($this->name.'trans_type')); start_table(TABLESTYLE2); + if ($fresh) { systypes_list_row(_("Transaction Type:"), $this->name.'trans_type'); diff --git a/includes/ui/items_cart.inc b/includes/ui/items_cart.inc index 1b61f5a1..858b05be 100644 --- a/includes/ui/items_cart.inc +++ b/includes/ui/items_cart.inc @@ -38,6 +38,8 @@ class items_cart var $tax_info; // tax info for the GL transaction + var $fixed_asset; + function items_cart($type, $trans_no=0) { $this->trans_type = $type; @@ -99,10 +101,10 @@ class items_cart $low_stock = array(); - if (!$SysPrefs->allow_negative_stock()) + if (!$SysPrefs->allow_negative_stock() || is_fixed_asset($line_item->mb_flag)) { foreach ($this->line_items as $line_no => $line_item) - if (has_stock_holding($line_item->mb_flag)) + if (has_stock_holding($line_item->mb_flag) || is_fixed_asset($line_item->mb_flag)) { $quantity = $line_item->quantity; if ($reverse) @@ -120,12 +122,12 @@ class items_cart // ----------- GL item functions - function add_gl_item($code_id, $dimension_id, $dimension2_id, $amount, $memo='', $act_descr=null, $person_id=null) + function add_gl_item($code_id, $dimension_id, $dimension2_id, $amount, $memo='', $act_descr=null, $person_id=null, $date=null) { if (isset($code_id) && $code_id != "" && isset($amount) && isset($dimension_id) && isset($dimension2_id)) { - $this->gl_items[] = new gl_item($code_id, $dimension_id, $dimension2_id, $amount, $memo, $act_descr, $person_id); + $this->gl_items[] = new gl_item($code_id, $dimension_id, $dimension2_id, $amount, $memo, $act_descr, $person_id, $date); return true; } else @@ -361,7 +363,10 @@ class items_cart $total_gl = 0; foreach($this->gl_items as $gl) { - $total_gl += add_gl_trans($this->trans_type, $this->order_id, $this->tran_date, $gl->code_id, $gl->dimension_id, $gl->dimension2_id, + if (!isset($gl->date)) + $gl->date = $this->tran_date; + + $total_gl += add_gl_trans($this->trans_type, $this->order_id, $gl->date, $gl->code_id, $gl->dimension_id, $gl->dimension2_id, $gl->reference, $gl->amount, $this->currency, $gl->person_type_id, $gl->person_id, "", $this->rate); // post to first found bank account using given gl acount code. @@ -502,9 +507,10 @@ class gl_item var $person_type_id; var $person_name; var $branch_id; + var $date; function gl_item($code_id=null, $dimension_id=0, $dimension2_id=0, $amount=0, $memo='', - $act_descr=null, $person_id=null) + $act_descr=null, $person_id=null, $date=null) { //echo "adding $index, $code_id, $dimension_id, $amount, $reference
"; @@ -527,5 +533,6 @@ class gl_item $this->dimension2_id = $dimension2_id; $this->amount = round($amount, 2); $this->reference = $memo; + $this->date = $date; } } diff --git a/includes/ui/ui_controls.inc b/includes/ui/ui_controls.inc index 54712f9c..ba62f467 100644 --- a/includes/ui/ui_controls.inc +++ b/includes/ui/ui_controls.inc @@ -509,6 +509,8 @@ $popup_editors = array( 'supplier' => array('/purchasing/manage/suppliers.php?supplier_id=', 113, _("Suppliers"), 900, 700), 'item' => array('/inventory/manage/items.php?stock_id=', + 115, _("Items"), 800, 600), + 'fa_item' => array('/inventory/manage/items.php?FixedAsset=1&stock_id=', 115, _("Items"), 800, 600) ); /* diff --git a/includes/ui/ui_input.inc b/includes/ui/ui_input.inc index 5aa4f569..f5f87cff 100644 --- a/includes/ui/ui_input.inc +++ b/includes/ui/ui_input.inc @@ -734,7 +734,7 @@ function ref_cells($label, $name, $title=null, $init=null, $params=null, $submit { $_POST[$name] = $init; } else { - $_POST[$name] = $Refs->get_next($type, $_POST[$name.'_list'], $context); // set default + $_POST[$name] = $Refs->get_next($type, $_POST[$name.'_list'], $context); } $Ajax->addUpdate(true, $name, $_POST[$name]); } diff --git a/includes/ui/ui_lists.inc b/includes/ui/ui_lists.inc index 0d15e749..d62b8436 100644 --- a/includes/ui/ui_lists.inc +++ b/includes/ui/ui_lists.inc @@ -401,7 +401,14 @@ $opts = array( // default options return $selector; } //---------------------------------------------------------------------------------------------- +function array_selector_row($label, $name, $selected_id, $items, $options=null) +{ + echo "$label\n"; + echo array_selector($name, $selected_id, $items, $options); + echo "\n"; +} +//---------------------------------------------------------------------------------------------- function _format_add_curr($row) { static $company_currency; @@ -580,10 +587,10 @@ function customer_branches_list_row($label, $customer_id, $name, $selected_id=nu //------------------------------------------------------------------------------------------------ -function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false) +function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false) { - $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations"; + $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations WHERE fixed_asset=".(int)$fixed_asset; return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name', array( @@ -593,19 +600,19 @@ function locations_list($name, $selected_id=null, $all_option=false, $submit_on_ ) ); } -function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false) +function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false) { if ($label != null) echo "$label\n"; echo ""; - echo locations_list($name, $selected_id, $all_option, $submit_on_change); + echo locations_list($name, $selected_id, $all_option, $submit_on_change, $fixed_asset); echo "\n"; } -function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false) +function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false) { echo "$label"; - locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change); + locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change, $fixed_asset); echo "\n"; } @@ -731,6 +738,11 @@ function stock_items_list($name, $selected_id=null, $all_option=false, $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id"; + if (isset($opts['fixed_asset']) && $opts['fixed_asset']) + $sql .= " AND mb_flag='F'"; + else + $sql .= " AND mb_flag!='F'"; + if ($editkey) set_editor('item', $name, $editkey); @@ -762,10 +774,25 @@ function _format_stock_items($row) function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $all=false, $editkey = false, $opts= array()) { + if (isset($opts['fixed_asset']) && $opts['fixed_asset']) + $editor_item = 'fa_item'; + else + $editor_item = 'item'; + +// if ($editkey) ?? +// set_editor($editor_item, $name, $editkey); + if ($label != null) echo "$label\n"; + +// ?? +// $opts = array_merge($options, array('cells'=>true, 'show_inactive'=>$all, 'new_icon' => $editkey ? 'item' : false)); +// +// echo stock_items_list($name, $selected_id, $all_option, $submit_on_change, $opts); + echo stock_items_list($name, $selected_id, $all_option, $submit_on_change, array_merge(array('cells'=>true, 'show_inactive'=>$all), $opts), $editkey); + } /* function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false) @@ -791,7 +818,8 @@ function sales_items_list($name, $selected_id=null, $all_option=false, LEFT JOIN ".TB_PREF."stock_category c ON i.category_id=c.category_id - WHERE i.stock_id=s.stock_id"; + WHERE i.stock_id=s.stock_id + AND mb_flag != 'F'"; if ($type == 'local') { // exclude foreign codes @@ -967,6 +995,90 @@ function stock_units_list_row($label, $name, $value=null, $enabled=true) //------------------------------------------------------------------------------------ +function stock_purchasable_fa_list_cells($label, $name, $selected_id=null, $all_option=false, + $submit_on_change=false, $all=false, $editkey = false, $exclude_items = array()) +{ + // Check if a fixed asset has been bought. + $where_opts[] = "stock_id NOT IN + ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )"; + + // exclude items currently on the order. + foreach($exclude_items as $item) { + $where_opts[] = "stock_id != ".db_escape($item->stock_id); + } + $where_opts[] = "mb_flag='F'"; + + echo stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change, $all, $editkey, + array('fixed_asset' => true, 'where' => $where_opts)); +} + +function stock_disposable_fa_list($name, $selected_id=null, + $all_option=false, $submit_on_change=false) +{ + // Check if a fixed asset has been bought.... + $where_opts[] = "stock_id IN + ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )"; + // ...but has not been disposed or sold already. + $where_opts[] = "stock_id NOT IN + ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )"; + + $where_opts[] = "mb_flag='F'"; + + echo stock_items_list($name, $selected_id, $all_option, $submit_on_change, + array('fixed_asset' => true, 'where' => $where_opts)); +} + +function stock_disposable_fa_list_cells($label, $name, $selected_id=null, + $all_option=false, $submit_on_change=false, $exclude_items = array()) +{ + // Check if a fixed asset has been bought.... + $where_opts[] = "stock_id IN + ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )"; + // ...but has not been disposed or sold already. + $where_opts[] = "stock_id NOT IN + ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )"; + + $where_opts[] = "mb_flag='F'"; + + foreach($exclude_items as $item) { + $where_opts[] = "stock_id != ".db_escape($item->stock_id); + } + + if ($label != null) + echo "$label\n"; + echo stock_items_list($name, $selected_id, $all_option, $submit_on_change, + array('fixed_asset' => true, 'cells'=>true, 'where' => $where_opts)); +} + +function stock_depreciable_fa_list_cells($label, $name, $selected_id=null, + $all_option=false, $submit_on_change=false) +{ + + // Check if a fixed asset has been bought.... + $where_opts[] = "stock_id IN + ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )"; + // ...but has not been disposed or sold already. + $where_opts[] = "stock_id NOT IN + ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )"; + + $year = get_current_fiscalyear(); + $y = date('Y', strtotime($year['end'])); + + // check if current fiscal year + $where_opts[] = "depreciation_date < '".$y."-12-01'"; + $where_opts[] = "depreciation_date >= '".($y-1)."-12-01'"; + + $where_opts[] = "material_cost > 0"; + $where_opts[] = "mb_flag='F'"; + + if ($label != null) + echo "$label\n"; + echo stock_items_list($name, $selected_id, $all_option, $submit_on_change, + array('fixed_asset' => true, 'where' => $where_opts, 'cells'=>true)); +} + +//------------------------------------------------------------------------------------ + function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false) { $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types"; @@ -1503,34 +1615,71 @@ function class_list_row($label, $name, $selected_id=null, $submit_on_change=fals } //----------------------------------------------------------------------------------------------- -function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false) +function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false) { + $where_opts = array(); + if ($fixed_asset) + $where_opts[0] = "dflt_mb_flag='F'"; + else + $where_opts[0] = "dflt_mb_flag!='F'"; + $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category"; return combo_input($name, $selected_id, $sql, 'category_id', 'description', array('order'=>'category_id', 'spec_option' => $spec_opt, 'spec_id' => -1, 'select_submit'=> $submit_on_change, - 'async' => true + 'async' => true, + 'where' => $where_opts, )); } -function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false) +function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false) { if ($label != null) echo "$label\n"; echo ""; - echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change); + echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change, $fixed_asset); echo "\n"; } -function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false) +function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false) { echo "$label"; - stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change); + stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change, $fixed_asset); echo "\n"; } +//----------------------------------------------------------------------------------------------- +function fixed_asset_classes_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false) +{ + $sql = "SELECT c.fa_class_id, CONCAT(c.fa_class_id,' - ',c.description) `desc`, CONCAT(p.fa_class_id,' - ',p.description), c.inactive FROM ".TB_PREF."stock_fa_class c, ".TB_PREF."stock_fa_class p WHERE c.parent_id=p.fa_class_id"; + + return combo_input($name, $selected_id, $sql, 'c.fa_class_id', 'desc', + array('order'=>'c.fa_class_id', + 'spec_option' => $spec_opt, + 'spec_id' => -1, + 'select_submit'=> $submit_on_change, + 'async' => true, + 'search_box' => true, + 'search' => array("c.fa_class_id"), + 'search_submit' => false, + 'spec_option' => '', + 'spec_id' => '', + 'size' => 3, + 'max' => 3, + 'category' => 2, + )); +} + +function fixed_asset_classes_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false) +{ + echo "$label"; + echo ""; + echo fixed_asset_classes_list($name, $selected_id, $spec_opt, $submit_on_change); + echo "\n"; +} + //----------------------------------------------------------------------------------------------- function gl_account_types_list($name, $selected_id=null, $all_option=false, $all=true) diff --git a/install/lang/es_MX/LC_MESSAGES/es_MX.po b/install/lang/es_MX/LC_MESSAGES/es_MX.po index 8d636c3d..f2e0a5d0 100644 --- a/install/lang/es_MX/LC_MESSAGES/es_MX.po +++ b/install/lang/es_MX/LC_MESSAGES/es_MX.po @@ -390,7 +390,7 @@ msgstr "Falta archivo de traducci #: /includes/system_tests.inc:276 #, php-format msgid "Missing system locale: %s" -msgstr "Falta configuración regional del sistema:" +msgstr "Falta configuración regional del sistema: %s" #: /includes/system_tests.inc:289 msgid "Main config file" @@ -399,7 +399,7 @@ msgstr "Archivo de configuraci #: /includes/system_tests.inc:296 /includes/system_tests.inc:318 #, php-format msgid "Can't write '%s' file. Check FA directory write permissions." -msgstr "No se puede escribir el archivo '% s'. Compruebe que el sistema tiene permisos de escritura." +msgstr "No se puede escribir el archivo '%s'. Compruebe que el sistema tiene permisos de escritura." #: /includes/system_tests.inc:297 /includes/system_tests.inc:319 #, php-format @@ -409,7 +409,7 @@ msgstr "Ya existe el archivo '%s'" #: /includes/system_tests.inc:301 #, php-format msgid "'%s' file should be read-only" -msgstr "El archivo '% s' debe ser de sólo lectura" +msgstr "El archivo '%s' debe ser de sólo lectura" #: /includes/system_tests.inc:310 msgid "Database auth file" @@ -418,7 +418,7 @@ msgstr "Archivo de autenticaci #: /includes/system_tests.inc:323 #, php-format msgid "'%s' file should be read-only if you do not plan to add or change companies" -msgstr "El archivo '% s' debe ser de sólo lectura si no vas a agregar o cambiar empresa" +msgstr "El archivo '%s' debe ser de sólo lectura si no vas a agregar o cambiar empresa" #: /includes/system_tests.inc:334 msgid "Extensions system" @@ -431,7 +431,7 @@ msgstr "Los archivos y directorios de configuraci #: /includes/system_tests.inc:385 #, php-format msgid "Non-standard theme directory '%s' is not writable" -msgstr "El directorio del tema '% S' no tiene permisos de escritura" +msgstr "El directorio del tema '%s' no tiene permisos de escritura" #: /includes/system_tests.inc:395 msgid "OpenSSL PHP extension have to be enabled to use extension repository system." diff --git a/inventory/adjustments.php b/inventory/adjustments.php index f71bb920..b82a6122 100644 --- a/inventory/adjustments.php +++ b/inventory/adjustments.php @@ -18,6 +18,7 @@ include_once($path_to_root . "/includes/session.inc"); include_once($path_to_root . "/includes/date_functions.inc"); include_once($path_to_root . "/includes/data_checks.inc"); +include_once($path_to_root . "/fixed_assets/includes/fixed_assets_db.inc"); include_once($path_to_root . "/inventory/includes/item_adjustments_ui.inc"); include_once($path_to_root . "/inventory/includes/inventory_db.inc"); $js = ""; @@ -25,11 +26,15 @@ if ($SysPrefs->use_popup_windows) $js .= get_js_open_window(800, 500); if (user_use_date_picker()) $js .= get_js_date_picker(); -page(_($help_context = "Item Adjustments Note"), false, false, "", $js); - -//----------------------------------------------------------------------------------------------- - -check_db_has_costable_items(_("There are no inventory items defined in the system which can be adjusted (Purchased or Manufactured).")); +if (isset($_GET['NewAdjustment'])) { + if (isset($_GET['FixedAsset'])) { + $page_security = 'SA_ASSETDISPOSAL'; + $_SESSION['page_title'] = _($help_context = "FA Disposal"); + } else { + $_SESSION['page_title'] = _($help_context = "Item Adjustments Note"); + } +} +page($_SESSION['page_title'], false, false, "", $js); //----------------------------------------------------------------------------------------------- @@ -38,12 +43,24 @@ if (isset($_GET['AddedID'])) $trans_no = $_GET['AddedID']; $trans_type = ST_INVADJUST; - display_notification_centered(_("Items adjustment has been processed")); - display_note(get_trans_view_str($trans_type, $trans_no, _("&View this adjustment"))); + $result = get_stock_adjustment_items($trans_no); + $row = db_fetch($result); + + if (is_fixed_asset($row['mb_flag'])) { + display_notification_centered(_("FA disposal has been processed")); + display_note(get_trans_view_str($trans_type, $trans_no, _("&View this disposal"))); - display_note(get_gl_view_str($trans_type, $trans_no, _("View the GL &Postings for this Adjustment")), 1, 0); + display_note(get_gl_view_str($trans_type, $trans_no, _("View the GL &Postings for this Disposal")), 1, 0); + hyperlink_params($_SERVER['PHP_SELF'], _("Enter &Another Disposal"), "NewAdjustment=1&FixedAsset=1"); + } + else { + display_notification_centered(_("Items adjustment has been processed")); + display_note(get_trans_view_str($trans_type, $trans_no, _("&View this adjustment"))); - hyperlink_no_params($_SERVER['PHP_SELF'], _("Enter &Another Adjustment")); + display_note(get_gl_view_str($trans_type, $trans_no, _("View the GL &Postings for this Adjustment")), 1, 0); + + hyperlink_params($_SERVER['PHP_SELF'], _("Enter &Another Adjustment"), "NewAdjustment=1"); + } hyperlink_params("$path_to_root/admin/attachments.php", _("Add an Attachment"), "filterType=$trans_type&trans_no=$trans_no"); @@ -68,6 +85,7 @@ function handle_new_order() } $_SESSION['adj_items'] = new items_cart(ST_INVADJUST); + $_SESSION['adj_items']->fixed_asset = isset($_GET['FixedAsset']); $_POST['AdjDate'] = new_doc_date(); if (!is_date_in_fiscalyear($_POST['AdjDate'])) $_POST['AdjDate'] = end_fiscalyear(); @@ -124,12 +142,17 @@ function can_process() if (isset($_POST['Process']) && can_process()){ + $fixed_asset = $_SESSION['adj_items']->fixed_asset; + $trans_no = add_stock_adjustment($_SESSION['adj_items']->line_items, $_POST['StockLocation'], $_POST['AdjDate'], $_POST['ref'], $_POST['memo_']); new_doc_date($_POST['AdjDate']); $_SESSION['adj_items']->clear_items(); unset($_SESSION['adj_items']); + if ($fixed_asset) + meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no&FixedAsset=1"); + else meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no"); } /*end of process credit note */ @@ -200,23 +223,37 @@ if (isset($_POST['CancelItemChanges'])) { if (isset($_GET['NewAdjustment']) || !isset($_SESSION['adj_items'])) { + + if (isset($_GET['FixedAsset'])) + check_db_has_disposable_fixed_assets(_("There are no fixed assets defined in the system.")); + else + check_db_has_costable_items(_("There are no inventory items defined in the system which can be adjusted (Purchased or Manufactured).")); + handle_new_order(); } //----------------------------------------------------------------------------------------------- start_form(); +if ($_SESSION['adj_items']->fixed_asset) { + $items_title = _("Disposal Items"); + $button_title = _("Process Disposal"); +} else { + $items_title = _("Adjustment Items"); + $button_title = _("Process Adjustment"); +} + display_order_header($_SESSION['adj_items']); start_outer_table(TABLESTYLE, "width='70%'", 10); -display_adjustment_items(_("Adjustment Items"), $_SESSION['adj_items']); +display_adjustment_items($items_title, $_SESSION['adj_items']); adjustment_options_controls(); end_outer_table(1, false); submit_center_first('Update', _("Update"), '', null); -submit_center_last('Process', _("Process Adjustment"), '', 'default'); +submit_center_last('Process', $button_title, '', 'default'); end_form(); end_page(); diff --git a/inventory/cost_update.php b/inventory/cost_update.php index 11ab6fc3..6fa3a019 100644 --- a/inventory/cost_update.php +++ b/inventory/cost_update.php @@ -27,11 +27,21 @@ include_once($path_to_root . "/includes/ui/items_cart.inc"); $js = ""; if ($SysPrefs->use_popup_windows) $js .= get_js_open_window(900, 500); -page(_($help_context = "Inventory Item Cost Update"), false, false, "", $js); + +if (isset($_GET['FixedAsset'])) { + $_SESSION['page_title'] = _($help_context = "FA Revaluation"); + $_POST['fixed_asset'] = 1; +} else { + $_SESSION['page_title'] = _($help_context = "Inventory Item Cost Update"); +} +page($_SESSION['page_title'], false, false, "", $js); //-------------------------------------------------------------------------------------- -check_db_has_costable_items(_("There are no costable inventory items defined in the system (Purchased or manufactured items).")); +if (get_post('fixed_asset') == 1) + check_db_has_disposable_fixed_assets(_("There are no fixed assets defined in the system.")); +else + check_db_has_costable_items(_("There are no costable inventory items defined in the system (Purchased or manufactured items).")); if (isset($_GET['stock_id'])) { @@ -39,6 +49,7 @@ if (isset($_GET['stock_id'])) } //-------------------------------------------------------------------------------------- +$should_update = false; if (isset($_POST['UpdateData'])) { @@ -66,7 +77,8 @@ if (isset($_POST['UpdateData'])) { $update_no = stock_cost_update($_POST['stock_id'], input_num('material_cost'), input_num('labour_cost'), - input_num('overhead_cost'), $old_cost); + input_num('overhead_cost'), $old_cost, + $_POST['refline'], $_POST['memo_']); display_notification(_("Cost has been updated.")); @@ -78,8 +90,10 @@ if (isset($_POST['UpdateData'])) } } -if (list_updated('stock_id')) +if (list_updated('stock_id') || $should_update) { + unset($_POST['memo_']); $Ajax->activate('cost_table'); +} //----------------------------------------------------------------------------------------- $action = $_SERVER['PHP_SELF']; @@ -87,13 +101,18 @@ if ($page_nested) $action .= "?stock_id=".get_post('stock_id'); start_form(false, false, $action); +hidden('fixed_asset'); + if (!isset($_POST['stock_id'])) $_POST['stock_id'] = get_global_stock_item(); if (!$page_nested) { echo "
" . _("Item:"). " "; - echo stock_items_list('stock_id', $_POST['stock_id'], false, true); + if (get_post('fixed_asset') == 1) + echo stock_disposable_fa_list('stock_id', $_POST['stock_id'], false, true); + else + echo stock_items_list('stock_id', $_POST['stock_id'], false, true); echo "

"; } @@ -124,6 +143,8 @@ else hidden("labour_cost", 0); hidden("overhead_cost", 0); } +refline_list_row(_("Reference line:"), 'refline', ST_COSTUPDATE, null, false, get_post('fixed_asset')); +textarea_row(_("Memo"), 'memo_', null, 40, 4); end_table(1); div_end(); diff --git a/inventory/includes/db/items_adjust_db.inc b/inventory/includes/db/items_adjust_db.inc index 205b782e..605206cb 100644 --- a/inventory/includes/db/items_adjust_db.inc +++ b/inventory/includes/db/items_adjust_db.inc @@ -94,17 +94,39 @@ function add_stock_adjustment_item($adj_id, $stock_id, $location, $date_, $refer update_average_material_cost(null, $stock_id, $standard_cost, $quantity, $date_); + if (is_fixed_asset($mb_flag)) { + $sql = "UPDATE ".TB_PREF."stock_master SET inactive=1 + WHERE stock_id=".db_escape($stock_id); + db_query($sql,"The inactive flag for the fixed asset could not be updated"); + } + add_stock_move(ST_INVADJUST, $stock_id, $adj_id, $location, $date_, $reference, $quantity, $standard_cost); - if ($standard_cost > 0) + $inv_value = $standard_cost * $quantity; + $adj_value = $standard_cost * -($quantity); + + if (is_fixed_asset($mb_flag)) { + // get the initial value of the fixed assset. + $row = get_fixed_asset_move($stock_id, ST_SUPPRECEIVE); + $inv_value = $row['price'] * $quantity; + $adj_value = (-($row['price']) + $standard_cost) * $quantity; + } + + if ($standard_cost > 0 || is_fixed_asset($mb_flag)) { $stock_gl_codes = get_stock_gl_code($stock_id); add_gl_trans_std_cost(ST_INVADJUST, $adj_id, $date_, - $stock_gl_codes['adjustment_account'], $stock_gl_codes['dimension_id'], $stock_gl_codes['dimension2_id'], $memo_, ($standard_cost * -($quantity))); + $stock_gl_codes['adjustment_account'], $stock_gl_codes['dimension_id'], $stock_gl_codes['dimension2_id'], $memo_, $adj_value ); + + add_gl_trans_std_cost(ST_INVADJUST, $adj_id, $date_, $stock_gl_codes['inventory_account'], 0, 0, $memo_, $inv_value); + } - add_gl_trans_std_cost(ST_INVADJUST, $adj_id, $date_, $stock_gl_codes['inventory_account'], 0, 0, $memo_, ($standard_cost * $quantity)); + if (is_fixed_asset($mb_flag)) { + // Additional gl entry for fixed asset. + $grn_act = get_company_pref('default_loss_on_asset_disposal_act'); + add_gl_trans_std_cost(ST_INVADJUST, $adj_id, $date_, $grn_act, 0, 0, $memo_, ($standard_cost * -($quantity))); } } diff --git a/inventory/includes/db/items_category_db.inc b/inventory/includes/db/items_category_db.inc index b454b881..3c643d52 100644 --- a/inventory/includes/db/items_category_db.inc +++ b/inventory/includes/db/items_category_db.inc @@ -66,12 +66,17 @@ function delete_item_category($id) db_query($sql,"an item category could not be deleted"); } -function get_item_categories($show_inactive) +function get_item_categories($show_inactive, $fixed_asset=false) { $sql = "SELECT c.*, t.name as tax_name FROM ".TB_PREF."stock_category c, " .TB_PREF."item_tax_types t WHERE c.dflt_tax_type=t.id"; if (!$show_inactive) $sql .= " AND !c.inactive"; + if ($fixed_asset) + $sql .= " AND c.dflt_mb_flag='F'"; + else + $sql .= " AND c.dflt_mb_flag!='F'"; + $sql .= " ORDER by description"; return db_query($sql, "could not get stock categories"); diff --git a/inventory/includes/db/items_db.inc b/inventory/includes/db/items_db.inc index 18f441e3..3806518e 100644 --- a/inventory/includes/db/items_db.inc +++ b/inventory/includes/db/items_db.inc @@ -12,7 +12,9 @@ function update_item($stock_id, $description, $long_description, $category_id, $tax_type_id, $units='', $mb_flag='', $sales_account, $inventory_account, $cogs_account, $adjustment_account, $assembly_account, $dimension_id, - $dimension2_id, $no_sale, $editable, $no_purchase) + $dimension2_id, $no_sale, $editable, $no_purchase, + $depreciation_method = 'D', $depreciation_rate=100, $depreciation_start=null, + $fa_class_id=null) { $sql = "UPDATE ".TB_PREF."stock_master SET long_description=".db_escape($long_description).", description=".db_escape($description).", @@ -27,7 +29,10 @@ function update_item($stock_id, $description, $long_description, $category_id, tax_type_id=".db_escape($tax_type_id).", no_sale=".db_escape($no_sale).", no_purchase=".db_escape($no_purchase).", - editable=".db_escape($editable); + editable=".db_escape($editable).", + depreciation_method=".db_escape($depreciation_method).", + depreciation_rate=".db_escape($depreciation_rate).", + fa_class_id=".db_escape($fa_class_id); if ($units != '') $sql .= ", units=".db_escape($units); @@ -35,6 +40,11 @@ function update_item($stock_id, $description, $long_description, $category_id, if ($mb_flag != '') $sql .= ", mb_flag=".db_escape($mb_flag); + if ($depreciation_start != '') { + $sql .= ", depreciation_start='".date2sql($depreciation_start)."'" + .", depreciation_date='".date2sql($depreciation_start)."'"; + } + $sql .= " WHERE stock_id=".db_escape($stock_id); db_query($sql, "The item could not be updated"); @@ -45,11 +55,14 @@ function update_item($stock_id, $description, $long_description, $category_id, function add_item($stock_id, $description, $long_description, $category_id, $tax_type_id, $units, $mb_flag, $sales_account, $inventory_account, $cogs_account, $adjustment_account, $assembly_account, $dimension_id, - $dimension2_id, $no_sale, $editable, $no_purchase) + $dimension2_id, $no_sale, $editable, $no_purchase, + $depreciation_method='D', $depreciation_rate=100, $depreciation_start=null, + $fa_class_id=null) { $sql = "INSERT INTO ".TB_PREF."stock_master (stock_id, description, long_description, category_id, tax_type_id, units, mb_flag, sales_account, inventory_account, cogs_account, - adjustment_account, assembly_account, dimension_id, dimension2_id, no_sale, no_purchase, editable) + adjustment_account, assembly_account, dimension_id, dimension2_id, no_sale, no_purchase, editable, + depreciation_method, depreciation_rate, depreciation_start, depreciation_date, fa_class_id) VALUES (".db_escape($stock_id).", ".db_escape($description).", ".db_escape($long_description).", ".db_escape($category_id).", ".db_escape($tax_type_id).", " .db_escape($units).", ".db_escape($mb_flag).", @@ -59,7 +72,10 @@ function add_item($stock_id, $description, $long_description, $category_id, .db_escape($dimension_id).", ".db_escape($dimension2_id)."," .db_escape($no_sale)."," .db_escape($no_purchase)."," - .db_escape($editable).")"; + .db_escape($editable)."," + .db_escape($depreciation_method).",".db_escape($depreciation_rate).",'" + .date2sql($depreciation_start)."','".date2sql($depreciation_start)."'," + .db_escape($fa_class_id).")"; db_query($sql, "The item could not be added"); @@ -108,9 +124,9 @@ function get_item($stock_id) return db_fetch($result); } -function get_items() +function get_items($fixed_asset = 0) { - $sql = "SELECT * FROM ".TB_PREF."stock_master"; + $sql = "SELECT * FROM ".TB_PREF."stock_master WHERE fixed_asset=".db_escape($fixed_asset); return db_query($sql,"items could not be retreived"); } diff --git a/inventory/includes/db/items_locations_db.inc b/inventory/includes/db/items_locations_db.inc index cab396e5..e85d39a1 100644 --- a/inventory/includes/db/items_locations_db.inc +++ b/inventory/includes/db/items_locations_db.inc @@ -9,12 +9,12 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License here . ***********************************************************************/ -function add_item_location($loc_code, $location_name, $delivery_address, $phone, $phone2, $fax, $email, $contact) +function add_item_location($loc_code, $location_name, $delivery_address, $phone, $phone2, $fax, $email, $contact, $fixed_asset = 0) { - $sql = "INSERT INTO ".TB_PREF."locations (loc_code, location_name, delivery_address, phone, phone2, fax, email, contact) + $sql = "INSERT INTO ".TB_PREF."locations (loc_code, location_name, delivery_address, phone, phone2, fax, email, contact, fixed_asset) VALUES (".db_escape($loc_code).", ".db_escape($location_name).", ".db_escape($delivery_address).", " .db_escape($phone).", ".db_escape($phone2).", ".db_escape($fax).", ".db_escape($email).", " - .db_escape($contact).")"; + .db_escape($contact).", ".db_escape($fixed_asset).")"; db_query($sql,"a location could not be added"); @@ -27,13 +27,14 @@ function add_item_location($loc_code, $location_name, $delivery_address, $phone, //------------------------------------------------------------------------------------ -function update_item_location($loc_code, $location_name, $delivery_address, $phone, $phone2, $fax, $email, $contact) +function update_item_location($loc_code, $location_name, $delivery_address, $phone, $phone2, $fax, $email, $contact, $fixed_asset = 0) { $sql = "UPDATE ".TB_PREF."locations SET location_name=".db_escape($location_name).", delivery_address=".db_escape($delivery_address).", phone=".db_escape($phone).", phone2=".db_escape($phone2).", fax=".db_escape($fax).", - email=".db_escape($email).", contact=".db_escape($contact)." + email=".db_escape($email).", contact=".db_escape($contact).", + fixed_asset=".db_escape($fixed_asset)." WHERE loc_code = ".db_escape($loc_code); db_query($sql,"a location could not be updated"); @@ -63,11 +64,11 @@ function get_item_location($item_location) //------------------------------------------------------------------------------------ -function get_item_locations($show_inactive) +function get_item_locations($show_inactive, $fixed_asset = 0) { - $sql = "SELECT * FROM ".TB_PREF."locations"; - if (!$show_inactive) $sql .= " WHERE !inactive"; - return db_query($sql, "could not query locations");; + $sql = "SELECT * FROM ".TB_PREF."locations WHERE fixed_asset = ".db_escape($fixed_asset); + if (!$show_inactive) $sql .= " AND !inactive"; + return db_query($sql, "could not query locations"); } //------------------------------------------------------------------------------------ @@ -82,13 +83,14 @@ function set_reorder_level($stock_id, $loc_code, $reorder_level) //------------------------------------------------------------------------------------ -function get_loc_details($stock_id) +function get_loc_details($stock_id, $fixed_asset = 0) { $sql = "SELECT stock.loc_code, stock.location_name, " .db_escape($stock_id)." as stock_id, reorders.reorder_level FROM ".TB_PREF."locations stock LEFT JOIN ".TB_PREF."loc_stock reorders ON reorders.loc_code=stock.loc_code AND reorders.stock_id = ".db_escape($stock_id) + ." WHERE stock.fixed_asset = ".db_escape($fixed_asset) ." ORDER BY reorders.loc_code"; return db_query($sql,"an item reorder could not be retreived"); } diff --git a/inventory/includes/db/items_trans_db.inc b/inventory/includes/db/items_trans_db.inc index c1264146..c97be95c 100644 --- a/inventory/includes/db/items_trans_db.inc +++ b/inventory/includes/db/items_trans_db.inc @@ -12,7 +12,7 @@ //------------------------------------------------------------------------------------------------------------- function stock_cost_update($stock_id, $material_cost, $labour_cost, $overhead_cost, - $last_cost) + $last_cost, $refline, $memo_) { $mb_flag = get_mb_flag($stock_id); @@ -33,7 +33,7 @@ function stock_cost_update($stock_id, $material_cost, $labour_cost, $overhead_co $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=".db_escape($material_cost).", labour_cost=".db_escape($labour_cost).", overhead_cost=".db_escape($overhead_cost).", - last_cost=".db_escape($last_cost)." + last_cost=".db_escape($last_cost)." WHERE stock_id=".db_escape($stock_id); db_query($sql,"The cost details for the inventory item could not be updated"); @@ -58,10 +58,13 @@ function stock_cost_update($stock_id, $material_cost, $labour_cost, $overhead_co $cart->tran_date = $cart->doc_date = $cart->event_date = $date_; if (!is_date_in_fiscalyear($cart->tran_date)) $cart->tran_date = end_fiscalyear(); - $cart->reference = $Refs->get_next(ST_COSTUPDATE, null, $cart->tran_date, $date_); - - $cart->memo_ = sprintf(_("Cost was %s changed to %s x quantity on hand of %s"), - number_format2($last_cost, 2), number_format2($new_cost), $qoh); + $cart->reference = $Refs->get_next(ST_COSTUPDATE, $refline, $cart->tran_date, $date_); + + if (empty($memo_)) + $cart->memo_ = sprintf(_("Cost was %s changed to %s x quantity on hand of %s"), + number_format2($last_cost, 2), number_format2($new_cost), $qoh); + else + $cart->memo_ = $memo_; $cart->add_gl_item($stock_gl_code["adjustment_account"], $stock_gl_code["dimension_id"], $stock_gl_code["dimension2_id"], -$value_of_change); @@ -85,6 +88,6 @@ function change_stock_moves_std_cost($stock_id, $date, $diff_cost) { $date = date2sql($date); $sql = "UPDATE ".TB_PREF."stock_moves SET standard_cost = standard_cost + ".db_escape($diff_cost). " WHERE stock_id = " - . db_escape($stock_id)." AND tran_date <= '$date' AND qty <> 0 AND standard_cost > 0.001 AND type <> ".ST_LOCTRANSFER; + .db_escape($stock_id)." AND tran_date <= '$date' AND qty <> 0 AND standard_cost > 0.001 AND type <> ".ST_LOCTRANSFER; db_query($sql,"The stock moves cost details for the inventory item could not be updated"); } diff --git a/inventory/includes/item_adjustments_ui.inc b/inventory/includes/item_adjustments_ui.inc index 4aa976cb..1331f62f 100644 --- a/inventory/includes/item_adjustments_ui.inc +++ b/inventory/includes/item_adjustments_ui.inc @@ -31,7 +31,7 @@ function display_order_header(&$order) start_outer_table(TABLESTYLE2, "width='70%'"); // outer table table_section(1); - locations_list_row(_("Location:"), 'StockLocation', null); + locations_list_row(_("Location:"), 'StockLocation', null, false, false, $order->fixed_asset); date_row(_("Date:"), 'AdjDate', '', true); table_section(2, "50%"); @@ -51,8 +51,15 @@ function display_adjustment_items($title, &$order) display_heading($title); div_start('items_table'); start_table(TABLESTYLE, "width='80%'"); - $th = array(_("Item Code"), _("Item Description"), _("Quantity"), + + if ($order->fixed_asset) { + $th = array(_("Item Code"), _("Item Description"), _("Quantity"), + _("Unit"), _("Unit Cost"), _("Initial Value"), ""); + } else { + $th = array(_("Item Code"), _("Item Description"), _("Quantity"), _("Unit"), _("Unit Cost"), _("Total"), ""); + if ( count($order->line_items)) $th[] = ''; + } if ( count($order->line_items)) $th[] = ''; table_header($th); @@ -73,17 +80,26 @@ function display_adjustment_items($title, &$order) else alt_table_row_color($k); - view_stock_status_cell($stock_item->stock_id); + if ($order->fixed_asset) + label_cell($stock_item->stock_id); + else + view_stock_status_cell($stock_item->stock_id); + label_cell($stock_item->item_description); qty_cell($stock_item->quantity, false, get_qty_dec($stock_item->stock_id)); label_cell($stock_item->units); amount_decimal_cell($stock_item->standard_cost); - amount_cell($stock_item->standard_cost * $stock_item->quantity); - edit_button_cell("Edit$line_no", _("Edit"), - _('Edit document line')); - delete_button_cell("Delete$line_no", _("Delete"), - _('Remove line from document')); + if ($order->fixed_asset) { + $price = get_initial_price($stock_item->stock_id); + amount_cell($price); + } else + amount_cell($stock_item->standard_cost * $stock_item->quantity); + + if (!$order->fixed_asset) { + edit_button_cell("Edit$line_no", _("Edit"), _('Edit document line')); + } + delete_button_cell("Delete$line_no", _("Delete"), _('Remove line from document')); end_row(); } else @@ -128,11 +144,17 @@ function adjustment_edit_item_controls(&$order, $line_no=-1) } else { - stock_costable_items_list_cells(null, 'stock_id', null, false, true); + if ($order->fixed_asset) + stock_disposable_fa_list_cells(null, 'stock_id', null, false, true, $order->line_items); + else + stock_costable_items_list_cells(null, 'stock_id', null, false, true); + if (list_updated('stock_id')) { $Ajax->activate('units'); $Ajax->activate('qty'); $Ajax->activate('std_cost'); + $Ajax->activate('std_cost_view'); + $Ajax->activate('initial_price'); } $item_info = get_item_edit_info($_POST['stock_id']); @@ -143,11 +165,26 @@ function adjustment_edit_item_controls(&$order, $line_no=-1) $_POST['units'] = $item_info["units"]; } - qty_cells(null, 'qty', $_POST['qty'], null, null, $dec); + if ($order->fixed_asset) { + hidden('qty', 1); + qty_cell(1, false, 0); + } else + qty_cells(null, 'qty', $_POST['qty'], null, null, $dec); + label_cell($_POST['units'], '', 'units'); - amount_cells(null, 'std_cost', null, null, null, $dec2); - label_cell(" "); + if ($order->fixed_asset) { + /* TODO: check if this is a correct way of creating a fixed item + that still has to be submitted in the form */ + hidden('std_cost'); + label_cell($_POST['std_cost'], "nowrap align=right ", 'std_cost_view'); + $price = get_initial_price($_POST['stock_id']); + amount_cell($price, false, '', 'initial_price'); + } else { + //amount_cells(null, 'std_cost', $_POST['std_cost']); + amount_cells(null, 'std_cost', null, null, null, $dec2); + label_cell(" "); + } if ($id != -1) { diff --git a/inventory/includes/stock_transfers_ui.inc b/inventory/includes/stock_transfers_ui.inc index f3c0f5dc..acc17772 100644 --- a/inventory/includes/stock_transfers_ui.inc +++ b/inventory/includes/stock_transfers_ui.inc @@ -32,14 +32,14 @@ function display_order_header(&$order) table_section(1); - locations_list_row(_("From Location:"), 'FromStockLocation', null); - locations_list_row(_("To Location:"), 'ToStockLocation', null); + locations_list_row(_("From Location:"), 'FromStockLocation', null, false, false, $order->fixed_asset); + locations_list_row(_("To Location:"), 'ToStockLocation', null,false, false, $order->fixed_asset); table_section(2, "50%"); date_row(_("Date:"), 'AdjDate', '', true); - ref_row(_("Reference:"), 'ref', '', $Refs->get_next(ST_LOCTRANSFER, null, array('date'=>get_post('Adjdate'), 'location'=> get_post('FromStockLocation'))), + ref_row(_("Reference:"), 'ref', '', $Refs->get_next(ST_LOCTRANSFER, null, array('date'=>get_post('AdjDate'), 'location'=> get_post('FromStockLocation'))), false, ST_LOCTRANSFER); end_outer_table(1); // outer table @@ -55,7 +55,7 @@ function display_transfer_items($title, &$order) div_start('items_table'); start_table(TABLESTYLE, "width='80%'"); $th = array(_("Item Code"), _("Item Description"), _("Quantity"), _("Unit"), ''); - if ( count($order->line_items)) $th[] = ''; + if (!$order->fixed_asset && count($order->line_items)) $th[] = ''; table_header($th); $k = 0; //row colour counter @@ -71,15 +71,17 @@ function display_transfer_items($title, &$order) else alt_table_row_color($k); - view_stock_status_cell($stock_item->stock_id); + if ($order->fixed_asset) + label_cell($stock_item->stock_id); + else + view_stock_status_cell($stock_item->stock_id); label_cell($stock_item->item_description); qty_cell($stock_item->quantity, false, get_qty_dec($stock_item->stock_id)); label_cell($stock_item->units); - edit_button_cell("Edit$line_no", _("Edit"), - _('Edit document line')); - delete_button_cell("Delete$line_no", _("Delete"), - _('Remove line from document')); + if (!$order->fixed_asset) + edit_button_cell("Edit$line_no", _("Edit"), _('Edit document line')); + delete_button_cell("Delete$line_no", _("Delete"), _('Remove line from document')); end_row(); } else @@ -118,7 +120,11 @@ function transfer_edit_item_controls(&$order, $line_no=-1) } else { - stock_costable_items_list_cells(null, 'stock_id', null, false, true); + if ($order->fixed_asset) + stock_disposable_fa_list_cells(null, 'stock_id', null, false, true, $order->line_items); + else + stock_costable_items_list_cells(null, 'stock_id', null, false, true); + if (list_updated('stock_id')) { $Ajax->activate('units'); $Ajax->activate('qty'); @@ -131,7 +137,12 @@ function transfer_edit_item_controls(&$order, $line_no=-1) $_POST['units'] = $item_info["units"]; } - small_qty_cells(null, 'qty', $_POST['qty'], null, null, $dec); + if ($order->fixed_asset) { + hidden('qty', 1); + qty_cell(1, false, 0); + } else + small_qty_cells(null, 'qty', $_POST['qty'], null, null, $dec); + label_cell($_POST['units'], '', 'units'); if ($id != -1) diff --git a/inventory/inquiry/stock_movements.php b/inventory/inquiry/stock_movements.php index a0783eab..f9ef425d 100644 --- a/inventory/inquiry/stock_movements.php +++ b/inventory/inquiry/stock_movements.php @@ -23,10 +23,22 @@ if ($SysPrefs->use_popup_windows) $js .= get_js_open_window(800, 500); if (user_use_date_picker()) $js .= get_js_date_picker(); -page(_($help_context = "Inventory Item Movement"), isset($_GET['stock_id']), false, "", $js); + +if (isset($_GET['FixedAsset'])) { + $page_security = 'SA_ASSETSTRANSVIEW'; + $_POST['fixed_asset'] = 1; + $_SESSION['page_title'] = _($help_context = "FA Item Movement"); +} else { + $_SESSION['page_title'] = _($help_context = "Inventory Item Movement"); +} + +page($_SESSION['page_title'], isset($_GET['stock_id']), false, "", $js); //------------------------------------------------------------------------------------------------ -check_db_has_stock_items(_("There are no items defined in the system.")); +if (get_post('fixed_asset') == 1) + check_db_has_fixed_assets(_("There are no fixed asset defined in the system.")); +else + check_db_has_stock_items(_("There are no items defined in the system.")); if(get_post('ShowMoves')) { @@ -40,20 +52,35 @@ if (isset($_GET['stock_id'])) start_form(); +hidden('fixed_asset'); + if (!isset($_POST['stock_id'])) $_POST['stock_id'] = get_global_stock_item(); start_table(TABLESTYLE_NOBORDER); start_row(); if (!$page_nested) - stock_costable_items_list_cells(_("Item:"), 'stock_id', $_POST['stock_id']); +{ + if (get_post('fixed_asset') == 1) { + stock_items_list_cells(_("Item:"), 'stock_id', $_POST['stock_id'], + false, false, check_value('show_inactive'), false, array('fixed_asset' => true)); + check_cells(_("Show inactive:"), 'show_inactive', null, true); + + if (get_post('_show_inactive_update')) { + $Ajax->activate('stock_id'); + set_focus('stock_id'); + } + } else + stock_costable_items_list_cells(_("Item:"), 'stock_id', $_POST['stock_id']); +} + end_row(); end_table(); start_table(TABLESTYLE_NOBORDER); start_row(); -locations_list_cells(_("From Location:"), 'StockLocation', null, true); +locations_list_cells(_("From Location:"), 'StockLocation', null, true, false, (get_post('fixed_asset') == 1)); date_cells(_("From:"), 'AfterDate', '', null, -user_transaction_days()); date_cells(_("To:"), 'BeforeDate'); @@ -108,7 +135,10 @@ while ($myrow = db_fetch($result)) $trandate = sql2date($myrow["tran_date"]); - $type_name = $systypes_array[$myrow["type"]]; + if (get_post('fixed_asset') == 1 && isset($fa_systypes_array[$myrow["type"]])) + $type_name = $fa_systypes_array[$myrow["type"]]; + else + $type_name = $systypes_array[$myrow["type"]]; if ($myrow["qty"] > 0) { diff --git a/inventory/manage/item_categories.php b/inventory/manage/item_categories.php index aca8e88a..d63354d1 100644 --- a/inventory/manage/item_categories.php +++ b/inventory/manage/item_categories.php @@ -13,7 +13,16 @@ $page_security = 'SA_ITEMCATEGORY'; $path_to_root = "../.."; include($path_to_root . "/includes/session.inc"); -page(_($help_context = "Item Categories")); +if (isset($_GET['FixedAsset'])) { + $page_security = 'SA_ASSETCATEGORY'; + $help_context = "FA Item Categories"; + $_POST['mb_flag'] = 'F'; +} +else { + $help_context = "Item Categories"; +} + +page(_($help_context)); include_once($path_to_root . "/includes/ui.inc"); @@ -83,21 +92,32 @@ if ($Mode == 'RESET') { $selected_id = -1; $sav = get_post('show_inactive'); + $mb_flag = get_post('mb_flag'); unset($_POST); $_POST['show_inactive'] = $sav; + if (is_fixed_asset($mb_flag)) + $_POST['mb_flag'] = 'F'; } if (list_updated('mb_flag')) { $Ajax->activate('details'); } + //---------------------------------------------------------------------------------- +$fixed_asset = is_fixed_asset(get_post('mb_flag')); -$result = get_item_categories(check_value('show_inactive')); +$result = get_item_categories(check_value('show_inactive'), $fixed_asset); start_form(); start_table(TABLESTYLE, "width='80%'"); -$th = array(_("Name"), _("Tax type"), _("Units"), _("Type"), _("Sales Act"), -_("Inventory Account"), _("COGS Account"), _("Adjustment Account"), -_("Assembly Account"), "", ""); +if ($fixed_asset) { + $th = array(_("Name"), _("Tax type"), _("Units"), _("Sales Act"), + _("Asset Account"), _("Deprecation Cost Account"), + _("Depreciation/Disposal Account"), "", ""); +} else { + $th = array(_("Name"), _("Tax type"), _("Units"), _("Type"), _("Sales Act"), + _("Inventory Account"), _("COGS Account"), _("Adjustment Account"), + _("Assembly Account"), "", ""); +} inactive_control_column($th); table_header($th); @@ -111,12 +131,14 @@ while ($myrow = db_fetch($result)) label_cell($myrow["description"]); label_cell($myrow["tax_name"]); label_cell($myrow["dflt_units"], "align=center"); - label_cell($stock_types[$myrow["dflt_mb_flag"]]); + if (!$fixed_asset) + label_cell($stock_types[$myrow["dflt_mb_flag"]]); label_cell($myrow["dflt_sales_act"], "align=center"); label_cell($myrow["dflt_inventory_act"], "align=center"); label_cell($myrow["dflt_cogs_act"], "align=center"); label_cell($myrow["dflt_adjustment_act"], "align=center"); - label_cell($myrow["dflt_assembly_act"], "align=center"); + if (!$fixed_asset) + label_cell($myrow["dflt_assembly_act"], "align=center"); inactive_control_cell($myrow["category_id"], $myrow["inactive"], 'stock_category', 'category_id'); edit_button_cell("Edit".$myrow["category_id"], _("Edit")); delete_button_cell("Delete".$myrow["category_id"], _("Delete")); @@ -185,11 +207,17 @@ table_section_title(_("Default values for new items")); item_tax_types_list_row(_("Item Tax Type:"), 'tax_type_id', null); -stock_item_types_list_row(_("Item Type:"), 'mb_flag', null, true); +if (is_fixed_asset(get_post('mb_flag'))) + hidden('mb_flag', 'F'); +else + stock_item_types_list_row(_("Item Type:"), 'mb_flag', null, true); stock_units_list_row(_("Units of Measure:"), 'units', null); -check_row(_("Exclude from sales:"), 'no_sale'); +if (is_fixed_asset($_POST['mb_flag'])) + hidden('no_sale', 0); +else + check_row(_("Exclude from sales:"), 'no_sale'); check_row(_("Exclude from purchases:"), 'no_purchase'); @@ -201,6 +229,12 @@ if (is_service($_POST['mb_flag'])) hidden('inventory_account', $_POST['inventory_account']); hidden('adjustment_account', $_POST['adjustment_account']); } +elseif (is_fixed_asset($_POST['mb_flag'])) +{ + gl_all_accounts_list_row(_("Asset account:"), 'inventory_account', $_POST['inventory_account']); + gl_all_accounts_list_row(_("Depreciation cost account:"), 'cogs_account', $_POST['cogs_account']); + gl_all_accounts_list_row(_("Depreciation/Disposal account:"), 'adjustment_account', $_POST['adjustment_account']); +} else { gl_all_accounts_list_row(_("Inventory Account:"), 'inventory_account', $_POST['inventory_account']); diff --git a/inventory/manage/items.php b/inventory/manage/items.php index fc7f1a7a..fbb75607 100644 --- a/inventory/manage/items.php +++ b/inventory/manage/items.php @@ -19,13 +19,27 @@ if ($SysPrefs->use_popup_windows) if (user_use_date_picker()) $js .= get_js_date_picker(); -page(_($help_context = "Items"), false, false, "", $js); +if (isset($_GET['FixedAsset'])) { + $page_security = 'SA_ASSET'; + $_SESSION['page_title'] = _($help_context = "FA Items"); + $_POST['mb_flag'] = 'F'; + $_POST['fixed_asset'] = 1; +} +else { + $_SESSION['page_title'] = _($help_context = "Items"); + if (!get_post('fixed_asset')) + $_POST['fixed_asset'] = 0; +} + + +page($_SESSION['page_title'], false, false, "", $js); include_once($path_to_root . "/includes/date_functions.inc"); include_once($path_to_root . "/includes/ui.inc"); include_once($path_to_root . "/includes/data_checks.inc"); include_once($path_to_root . "/inventory/includes/inventory_db.inc"); +include_once($path_to_root . "/fixed_assets/includes/fixed_assets_db.inc"); $user_comp = user_company(); $new_item = get_post('stock_id')=='' || get_post('cancel') || get_post('clone'); @@ -49,7 +63,7 @@ if (get_post('cancel')) { set_focus('stock_id'); $Ajax->activate('_page_body'); } -if (list_updated('category_id') || list_updated('mb_flag')) { +if (list_updated('category_id') || list_updated('mb_flag') || list_updated('fa_class_id') || list_updated('depreciation_method')) { $Ajax->activate('details'); } $upload_file = ""; @@ -118,7 +132,11 @@ if (isset($_FILES['pic']) && $_FILES['pic']['name'] != '') /* EOF Add Image upload for New Item - by Ori */ } -check_db_has_stock_categories(_("There are no item categories defined in the system. At least one item category is required to add a item.")); +if (get_post('fixed_asset')) { + check_db_has_fixed_asset_categories(_("There are no fixed asset categories defined in the system. At least one fixed asset category is required to add a fixed asset.")); + check_db_has_fixed_asset_classes(_("There are no fixed asset classes defined in the system. At least one fixed asset class is required to add a fixed asset.")); +} else + check_db_has_stock_categories(_("There are no item categories defined in the system. At least one item category is required to add a item.")); check_db_has_item_tax_types(_("There are no item tax types defined in the system. At least one item tax type is required to add a item.")); @@ -135,6 +153,9 @@ function clear_data() unset($_POST['dimension2_id']); unset($_POST['no_sale']); unset($_POST['no_purchase']); + unset($_POST['depreciation_method']); + unset($_POST['depreciation_rate']); + unset($_POST['depreciation_start']); } //------------------------------------------------------------------------------------ @@ -173,6 +194,19 @@ if (isset($_POST['addupdate'])) set_focus('NewStockID'); } + if (get_post('fixed_asset')) { + if ($_POST['depreciation_rate'] > 100) { + $_POST['depreciation_rate'] = 100; + } + elseif ($_POST['depreciation_rate'] < 0) { + $_POST['depreciation_rate'] = 0; + } + $move_row = get_fixed_asset_move($_POST['NewStockID'], ST_SUPPRECEIVE); + if (isset($_POST['depreciation_start']) && strtotime($_POST['depreciation_start']) < strtotime($move_row['tran_date'])) { + display_warning(_('The depracation cannot start before the fixed asset purchase date')); + } + } + if ($input_error != 1) { if (check_value('del_image')) @@ -187,11 +221,14 @@ if (isset($_POST['addupdate'])) update_item($_POST['NewStockID'], $_POST['description'], $_POST['long_description'], $_POST['category_id'], $_POST['tax_type_id'], get_post('units'), - get_post('mb_flag'), $_POST['sales_account'], + get_post('fixed_asset') ? 'F' : get_post('mb_flag'), $_POST['sales_account'], $_POST['inventory_account'], $_POST['cogs_account'], $_POST['adjustment_account'], $_POST['assembly_account'], $_POST['dimension_id'], $_POST['dimension2_id'], - check_value('no_sale'), check_value('editable'), check_value('no_purchase')); + check_value('no_sale'), check_value('editable'), check_value('no_purchase'), + get_post('depreciation_method'), get_post('depreciation_rate'), get_post('depreciation_start'), + get_post('fa_class_id')); + update_record_status($_POST['NewStockID'], $_POST['inactive'], 'stock_master', 'stock_id'); update_record_status($_POST['NewStockID'], $_POST['inactive'], @@ -205,11 +242,13 @@ if (isset($_POST['addupdate'])) add_item($_POST['NewStockID'], $_POST['description'], $_POST['long_description'], $_POST['category_id'], $_POST['tax_type_id'], - $_POST['units'], $_POST['mb_flag'], $_POST['sales_account'], + $_POST['units'], get_post('fixed_asset') ? 'F' : get_post('mb_flag'), $_POST['sales_account'], $_POST['inventory_account'], $_POST['cogs_account'], $_POST['adjustment_account'], $_POST['assembly_account'], $_POST['dimension_id'], $_POST['dimension2_id'], - check_value('no_sale'), check_value('editable'), check_value('no_purchase')); + check_value('no_sale'), check_value('editable'), check_value('no_purchase'), + get_post('depreciation_method'), get_post('depreciation_rate'), get_post('depreciation_start'), + get_post('fa_class_id')); display_notification(_("A new item has been added.")); $_POST['stock_id'] = $_POST['NewStockID'] = @@ -265,7 +304,7 @@ if (isset($_POST['delete']) && strlen($_POST['delete']) > 1) function item_settings(&$stock_id, $new_item) { - global $SysPrefs, $path_to_root, $page_nested; + global $SysPrefs, $path_to_root, $page_nested, $depreciation_methods; start_outer_table(TABLESTYLE2); @@ -295,6 +334,13 @@ function item_settings(&$stock_id, $new_item) $_POST['units'] = $myrow["units"]; $_POST['mb_flag'] = $myrow["mb_flag"]; + $_POST['depreciation_method'] = $myrow['depreciation_method']; + $_POST['depreciation_rate'] = $myrow['depreciation_rate']; + $_POST['depreciation_start'] = sql2date($myrow['depreciation_start']); + $_POST['depreciation_date'] = sql2date($myrow['depreciation_date']); + $_POST['fa_class_id'] = $myrow['fa_class_id']; + $_POST['material_cost'] = $myrow['material_cost']; + $_POST['sales_account'] = $myrow['sales_account']; $_POST['inventory_account'] = $myrow['inventory_account']; $_POST['cogs_account'] = $myrow['cogs_account']; @@ -312,12 +358,13 @@ function item_settings(&$stock_id, $new_item) hidden('NewStockID', $_POST['NewStockID']); set_focus('description'); } + $fixed_asset = get_post('fixed_asset'); text_row(_("Name:"), 'description', null, 52, 200); textarea_row(_('Description:'), 'long_description', null, 42, 3); - stock_categories_list_row(_("Category:"), 'category_id', null, false, $new_item); + stock_categories_list_row(_("Category:"), 'category_id', null, false, $new_item, $fixed_asset); if ($new_item && (list_updated('category_id') || !isset($_POST['units']))) { @@ -343,16 +390,64 @@ function item_settings(&$stock_id, $new_item) item_tax_types_list_row(_("Item Tax Type:"), 'tax_type_id', null); - stock_item_types_list_row(_("Item Type:"), 'mb_flag', null, $fresh_item); + if (!get_post('fixed_asset')) + stock_item_types_list_row(_("Item Type:"), 'mb_flag', null, $fresh_item); stock_units_list_row(_('Units of Measure:'), 'units', null, $fresh_item); check_row(_("Editable description:"), 'editable'); - check_row(_("Exclude from sales:"), 'no_sale'); + if (get_post('fixed_asset')) + hidden('no_sale', 0); + else + check_row(_("Exclude from sales:"), 'no_sale'); check_row(_("Exclude from purchases:"), 'no_purchase'); + if (get_post('fixed_asset')) { + table_section_title(_("Depreciation")); + + fixed_asset_classes_list_row(_("Fixed Asset Class").':', 'fa_class_id', null, false, true); + + array_selector_row(_("Depreciation Method").":", "depreciation_method", null, $depreciation_methods, array('select_submit'=> true)); + + if (!isset($_POST['depreciation_rate']) || (list_updated('fa_class_id') || list_updated('depreciation_method'))) { + $class_row = get_fixed_asset_class($_POST['fa_class_id']); + + if ($_POST['depreciation_method'] == 'S') + $_POST['depreciation_rate'] = $class_row['depreciation_period']; + else + $_POST['depreciation_rate'] = $class_row['depreciation_rate']; + } + + switch ($_POST['depreciation_method']) { + case 'D': + small_amount_row(_("Depreciation Rate").':', 'depreciation_rate', null, null, '%', user_percent_dec()); + break; + case 'S': + text_row_ex(_("Depreciation Period").':', 'depreciation_rate', 3, 3, '', null, null, _("years")); + break; + case 'O': + hidden('depreciation_rate', 100); + label_row(_("Depreciation Rate").':', "100 %"); + break; + } + + // do not allow to change the depreciation start after this item has been depreciated + if ($new_item || $_POST['depreciation_start'] == $_POST['depreciation_date']) + date_row(_("Depreciation Start").':', 'depreciation_start', null, null, 1 - date('j')); + else { + hidden('depreciation_start'); + label_row(_("Depreciation Start").':', $_POST['depreciation_start']); + label_row(_("Last Depreciation").':', $_POST['depreciation_date']); + } + hidden('depreciation_date'); + + if (!$new_item) { + hidden('material_cost'); + label_row(_("Current Value").':', price_format($_POST['material_cost'])); + } + } table_section(2); $dim = get_company_pref('use_dimension'); @@ -373,7 +468,12 @@ function item_settings(&$stock_id, $new_item) gl_all_accounts_list_row(_("Sales Account:"), 'sales_account', $_POST['sales_account']); - if (!is_service($_POST['mb_flag'])) + if (get_post('fixed_asset')) { + gl_all_accounts_list_row(_("Asset account:"), 'inventory_account', $_POST['inventory_account']); + gl_all_accounts_list_row(_("Depreciation cost account:"), 'cogs_account', $_POST['cogs_account']); + gl_all_accounts_list_row(_("Depreciation/Disposal account:"), 'adjustment_account', $_POST['adjustment_account']); + } + elseif (!is_service($_POST['mb_flag'])) { gl_all_accounts_list_row(_("Inventory Account:"), 'inventory_account', $_POST['inventory_account']); gl_all_accounts_list_row(_("C.O.G.S. Account:"), 'cogs_account', $_POST['cogs_account']); @@ -448,7 +548,7 @@ if (db_has_stock_items()) start_table(TABLESTYLE_NOBORDER); start_row(); stock_items_list_cells(_("Select an item:"), 'stock_id', null, - _('New item'), true, check_value('show_inactive')); + _('New item'), true, check_value('show_inactive'), false, array('fixed_asset' => get_post('fixed_asset'))); $new_item = get_post('stock_id')==''; check_cells(_("Show inactive:"), 'show_inactive', null, true); end_row(); @@ -470,16 +570,22 @@ $stock_id = get_post('stock_id'); if (!$stock_id) unset($_POST['_tabs_sel']); // force settings tab for new customer -tabbed_content_start('tabs', array( +$tabs = (get_post('fixed_asset')) + ? array( + 'settings' => array(_('&General settings'), $stock_id), + 'movement' => array(_('&Transactions'), $stock_id) ) + : array( 'settings' => array(_('&General settings'), $stock_id), 'sales_pricing' => array(_('S&ales Pricing'), $stock_id), 'purchase_pricing' => array(_('&Purchasing Pricing'), $stock_id), 'standard_cost' => array(_('Standard &Costs'), $stock_id), 'reorder_level' => array(_('&Reorder Levels'), (is_inventory_item($stock_id) ? $stock_id : null)), 'movement' => array(_('&Transactions'), $stock_id), - 'status' => array(_('&Status'), $stock_id), - )); - + 'status' => array(_('&Status'), (is_inventory_item($stock_id) ? $stock_id : null)), + ); + +tabbed_content_start('tabs', $tabs); + switch (get_post('_tabs_sel')) { default: case 'settings': @@ -518,11 +624,17 @@ tabbed_content_start('tabs', array( include_once($path_to_root."/inventory/inquiry/stock_status.php"); break; }; + br(); tabbed_content_end(); div_end(); +hidden('fixed_asset', get_post('fixed_asset')); + +if (get_post('fixed_asset')) + hidden('mb_flag', 'F'); + end_form(); //------------------------------------------------------------------------------------ diff --git a/inventory/manage/locations.php b/inventory/manage/locations.php index d102acf8..2dae0a78 100644 --- a/inventory/manage/locations.php +++ b/inventory/manage/locations.php @@ -13,12 +13,19 @@ $page_security = 'SA_INVENTORYLOCATION'; $path_to_root = "../.."; include($path_to_root . "/includes/session.inc"); -page(_($help_context = "Inventory Locations")); include_once($path_to_root . "/includes/ui.inc"); include_once($path_to_root . "/inventory/includes/inventory_db.inc"); +if (isset($_GET['FixedAsset'])) { + $help_context = "FA Locations"; + $_POST['fixed_asset'] = 1; +} else + $help_context = "Inventory Locations"; + +page(_($help_context)); + simple_page_mode(true); if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') @@ -52,7 +59,7 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') { update_item_location($selected_id, $_POST['location_name'], $_POST['delivery_address'], - $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['email'], $_POST['contact']); + $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['email'], $_POST['contact'], $_POST['fixed_asset']); display_notification(_('Selected location has been updated')); } else @@ -61,7 +68,7 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') /*selected_id is null cos no item selected on first time round so must be adding a record must be submitting new entries in the new Location form */ add_item_location($_POST['loc_code'], $_POST['location_name'], $_POST['delivery_address'], - $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['email'], $_POST['contact']); + $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['email'], $_POST['contact'], $_POST['fixed_asset']); display_notification(_('New location has been added')); } @@ -135,11 +142,13 @@ if ($Mode == 'RESET') { $selected_id = -1; $sav = get_post('show_inactive'); + $sav2 = get_post('fixed_asset'); unset($_POST); $_POST['show_inactive'] = $sav; + $_POST['fixed_asset'] = $sav2; } -$result = get_item_locations(check_value('show_inactive')); +$result = get_item_locations(check_value('show_inactive'), get_post('fixed_asset', 0)); start_form(); start_table(TABLESTYLE); @@ -169,6 +178,7 @@ end_table(); echo '
'; start_table(TABLESTYLE2); +hidden("fixed_asset"); $_POST['email'] = ""; if ($selected_id != -1) diff --git a/inventory/transfers.php b/inventory/transfers.php index 12f19d28..0143b0b7 100644 --- a/inventory/transfers.php +++ b/inventory/transfers.php @@ -25,7 +25,17 @@ if ($SysPrefs->use_popup_windows) $js .= get_js_open_window(800, 500); if (user_use_date_picker()) $js .= get_js_date_picker(); -page(_($help_context = "Inventory Location Transfers"), false, false, "", $js); + +if (isset($_GET['NewTransfer'])) { + if (isset($_GET['FixedAsset'])) { + $page_security = 'SA_ASSETTRANSFER'; + $_SESSION['page_title'] = _($help_context = "FA Location Transfers"); + } + else { + $_SESSION['page_title'] = _($help_context = "Inventory Location Transfers"); + } +} +page($_SESSION['page_title'], false, false, "", $js); //----------------------------------------------------------------------------------------------- @@ -41,7 +51,12 @@ if (isset($_GET['AddedID'])) display_notification_centered(_("Inventory transfer has been processed")); display_note(get_trans_view_str($trans_type, $trans_no, _("&View this transfer"))); - hyperlink_no_params($_SERVER['PHP_SELF'], _("Enter &Another Inventory Transfer")); + $itm = db_fetch(get_stock_transfer_items($_GET['AddedID'])); + + if (is_fixed_asset($itm['mb_flag'])) + hyperlink_params($_SERVER['PHP_SELF'], _("Enter &Another FA Item Transfer"), "NewTransfer=1&FixedAsset=1"); + else + hyperlink_params($_SERVER['PHP_SELF'], _("Enter &Another Inventory Transfer"), "NewTransfer=1"); display_footer_exit(); } @@ -64,6 +79,7 @@ function handle_new_order() } $_SESSION['transfer_items'] = new items_cart(ST_LOCTRANSFER); + $_SESSION['transfer_items']->fixed_asset = isset($_GET['FixedAsset']); $_POST['AdjDate'] = new_doc_date(); if (!is_date_in_fiscalyear($_POST['AdjDate'])) $_POST['AdjDate'] = end_fiscalyear(); @@ -196,6 +212,11 @@ if (isset($_POST['CancelItemChanges'])) { if (isset($_GET['NewTransfer']) || !isset($_SESSION['transfer_items'])) { + if (isset($_GET['fixed_asset'])) + check_db_has_disposable_fixed_assets(_("There are no fixed assets defined in the system.")); + else + check_db_has_costable_items(_("There are no inventory items defined in the system (Purchased or manufactured items).")); + handle_new_order(); } diff --git a/purchasing/includes/po_class.inc b/purchasing/includes/po_class.inc index e891e649..7fdef203 100644 --- a/purchasing/includes/po_class.inc +++ b/purchasing/includes/po_class.inc @@ -45,6 +45,8 @@ class purch_order var $alloc; // sum of payments allocated var $prepayments = array(); + var $fixed_asset = false; + function purch_order() { /*Constructor function initialises a new purchase order object */ diff --git a/purchasing/includes/ui/po_ui.inc b/purchasing/includes/ui/po_ui.inc index 55690ee3..22b6caec 100644 --- a/purchasing/includes/ui/po_ui.inc +++ b/purchasing/includes/ui/po_ui.inc @@ -153,7 +153,7 @@ function display_po_header(&$order) if ($editable) { - ref_row(_("Reference:"), 'ref'); + ref_row(_("Reference:"), 'ref', '', null, false, $order->trans_type, array('date'=> @$_POST['OrderDate'])); } else { @@ -172,7 +172,7 @@ function display_po_header(&$order) dimensions_list_row(_('Dimension').':', 'dimension', null, true, _('Default'), false, 1); if (get_company_pref('use_dimension') == 2) dimensions_list_row(_('Dimension 2').':', 'dimension2', null, true, _('Default'), false, 2); - locations_list_row(_("Receive Into:"), 'StkLocation', null, false, true); + locations_list_row(_("Receive Into:"), 'StkLocation', null, false, true, $order->fixed_asset); table_section(3); @@ -216,8 +216,9 @@ function display_po_items(&$order, $editable=true) _("Required Delivery Date"), $order->tax_included ? _("Price after Tax") : _("Price before Tax"), _("Line Total"), ""); if ($order->trans_type != ST_PURCHORDER) array_remove($th, 5); - + if (count($order->line_items)) $th[] = ''; + table_header($th); $id = find_submit('Edit'); @@ -231,7 +232,11 @@ function display_po_items(&$order, $editable=true) alt_table_row_color($k); label_cell($po_line->stock_id); label_cell($po_line->item_description); - qty_cell($po_line->quantity, false, get_qty_dec($po_line->stock_id)); + if ($order->fixed_asset) + label_cell(1); + else + qty_cell($po_line->quantity, false, get_qty_dec($po_line->stock_id)); + qty_cell($po_line->qty_received, false, get_qty_dec($po_line->stock_id)); label_cell($po_line->units); if ($order->trans_type == ST_PURCHORDER) @@ -380,8 +385,12 @@ function po_item_controls(&$order, &$rowcounter, $line_no=-1) else { - // Manufcatured item can be purchased - stock_items_list_cells(null, 'stock_id', null, false, true, false, true, array('editable' => 30)); + // Manufactured item can be purchased + if ($order->fixed_asset) + stock_purchasable_fa_list_cells(null, 'stock_id', null, false, true, false, true, $order->line_items); + else + stock_items_list_cells(null, 'stock_id', null, false, true, false, true, array('editable' => 30)); + if (list_updated('stock_id')) { $Ajax->activate('price'); $Ajax->activate('units'); @@ -400,7 +409,12 @@ function po_item_controls(&$order, &$rowcounter, $line_no=-1) $qty_rcvd = ''; } - qty_cells(null, 'qty', null, null, null, $dec); + if ($order->fixed_asset) { + label_cell(1, '', 'qty'); + hidden('qty', 1); + } else + qty_cells(null, 'qty', null, null, null, $dec); + qty_cell($qty_rcvd, false, $dec); label_cell($_POST['units'], '', 'units'); diff --git a/purchasing/po_entry_items.php b/purchasing/po_entry_items.php index 244322e1..22f38381 100644 --- a/purchasing/po_entry_items.php +++ b/purchasing/po_entry_items.php @@ -53,9 +53,14 @@ if (isset($_GET['ModifyOrderNumber']) && is_numeric($_GET['ModifyOrderNumber'])) copy_from_cart(); } elseif (isset($_GET['NewInvoice'])) { - $_SESSION['page_title'] = _($help_context = "Direct Purchase Invoice Entry"); create_new_po(ST_SUPPINVOICE, 0); copy_from_cart(); + + if (isset($_GET['FixedAsset'])) { + $_SESSION['page_title'] = _($help_context = "Fixed Asset Purchase Invoice Entry"); + $_SESSION['PO']->fixed_asset = true; + } else + $_SESSION['page_title'] = _($help_context = "Direct Purchase Invoice Entry"); } page($_SESSION['page_title'], false, false, "", $js); @@ -67,8 +72,6 @@ if (isset($_GET['ModifyOrderNumber'])) check_db_has_suppliers(_("There are no suppliers defined in the system.")); -check_db_has_purchasable_items(_("There are no purchasable inventory items defined in the system.")); - //--------------------------------------------------------------------------------------------------------------- if (isset($_GET['AddedID'])) @@ -88,6 +91,7 @@ if (isset($_GET['AddedID'])) hyperlink_params($path_to_root . "/purchasing/po_receive_items.php", _("&Receive Items on this Purchase Order"), "PONumber=$order_no"); + // TODO, for fixed asset hyperlink_params($_SERVER['PHP_SELF'], _("Enter &Another Purchase Order"), "NewOrder=yes"); hyperlink_no_params($path_to_root."/purchasing/inquiry/po_search.php", _("Select An &Outstanding Purchase Order")); @@ -138,6 +142,11 @@ if (isset($_GET['AddedID'])) display_footer_exit(); } + +if ($_SESSION['PO']->fixed_asset) + check_db_has_purchasable_fixed_assets(_("There are no purchasable fixed assets defined in the system.")); +else + check_db_has_purchasable_items(_("There are no purchasable inventory items defined in the system.")); //-------------------------------------------------------------------------------------------------- function line_start_focus() { @@ -185,13 +194,18 @@ function handle_cancel_po() . "
" . _("The line item quantities may be modified to quantities more than already received. prices cannot be altered for lines that have already been received and quantities cannot be reduced below the quantity already received.")); return; } - + + $fixed_asset = $_SESSION['PO']->fixed_asset; + if($_SESSION['PO']->order_no != 0) - { delete_po($_SESSION['PO']->order_no); - } else { + else { unset($_SESSION['PO']); - meta_forward($path_to_root.'/index.php','application=AP'); + + if ($fixed_asset) + meta_forward($path_to_root.'/index.php','application=assets'); + else + meta_forward($path_to_root.'/index.php','application=AP'); } $_SESSION['PO']->clear_items(); diff --git a/sales/includes/cart_class.inc b/sales/includes/cart_class.inc index b4c7f8f5..dc6e81a6 100644 --- a/sales/includes/cart_class.inc +++ b/sales/includes/cart_class.inc @@ -81,6 +81,8 @@ class cart var $prepayments = array(); // allocation records for this document var $ex_rate; + var $fixed_asset = false; + //------------------------------------------------------------------------- // // $trans_no==0 => open new/direct document diff --git a/sales/includes/db/sales_delivery_db.inc b/sales/includes/db/sales_delivery_db.inc index 1b0912d4..6337ba7c 100644 --- a/sales/includes/db/sales_delivery_db.inc +++ b/sales/includes/db/sales_delivery_db.inc @@ -98,6 +98,14 @@ function write_sales_delivery(&$delivery,$bo_policy) -$delivery_line->qty_dispatched, $delivery_line->standard_cost, $line_price*(1-$delivery_line->discount_percent)); + $mb_flag = get_mb_flag($delivery_line->stock_id); + + if (is_fixed_asset($mb_flag)) { + $sql = "UPDATE ".TB_PREF."stock_master SET inactive=1 + WHERE stock_id=".db_escape($delivery_line->stock_id); + db_query($sql,"The cost details for the fixed asset could not be updated"); + } + $stock_gl_code = get_stock_gl_code($delivery_line->stock_id); // If there is a Customer Dimension, then override with this, @@ -119,8 +127,12 @@ function write_sales_delivery(&$delivery,$bo_policy) /*first the cost of sales entry*/ + $delivery_gl_code = $stock_gl_code["cogs_account"]; + if ($delivery->fixed_asset) + $delivery_gl_code = $stock_gl_code["adjustment_account"]; + add_gl_trans_std_cost(ST_CUSTDELIVERY, $delivery_no, - $delivery->document_date, $stock_gl_code["cogs_account"], $dim, $dim2, "", + $delivery->document_date, $delivery_gl_code, $dim, $dim2, "", $delivery_line->standard_cost * $delivery_line->qty_dispatched, PT_CUSTOMER, $delivery->customer_id, "The cost of sales GL posting could not be inserted"); @@ -220,3 +232,4 @@ function void_sales_delivery($type, $type_no, $transactions=true) if ($transactions) commit_transaction(); } + diff --git a/sales/includes/db/sales_invoice_db.inc b/sales/includes/db/sales_invoice_db.inc index 387575d0..54e4374a 100644 --- a/sales/includes/db/sales_invoice_db.inc +++ b/sales/includes/db/sales_invoice_db.inc @@ -183,7 +183,7 @@ function write_sales_invoice(&$invoice) add_comments(ST_SALESINVOICE, $invoice_no, $date_, $invoice->Comments); if ($trans_no == 0) { - $Refs->save(ST_SALESINVOICE, $invoice_no, $invoice->reference); + $Refs->save(ST_SALESINVOICE, $invoice_no, $invoice->reference, null, $invoice->fixed_asset); if ($invoice->payment_terms['cash_sale'] && $invoice->pos['pos_account']) { $amount = $items_total + $items_added_tax + $invoice->freight_cost + $freight_added_tax; diff --git a/sales/includes/db/sales_order_db.inc b/sales/includes/db/sales_order_db.inc index 05dbe246..7f3257af 100644 --- a/sales/includes/db/sales_order_db.inc +++ b/sales/includes/db/sales_order_db.inc @@ -72,7 +72,7 @@ function add_sales_order(&$order) } /* inserted line items into sales order details */ add_audit_trail($order->trans_type, $order_no, $order->document_date); - $Refs->save($order->trans_type, $order_no, $order->reference); + $Refs->save($order->trans_type, $order_no, $order->reference, null, $order->fixed_asset); hook_db_postwrite($order, $order->trans_type); commit_transaction(); @@ -209,7 +209,7 @@ function update_sales_order($order) if ($order->trans_type == ST_SALESORDER) reallocate_payments($order_no, ST_SALESORDER, $ord_date, $total, $allocs); add_audit_trail($order->trans_type, $order_no, $order->document_date, _("Updated.")); - $Refs->save($order->trans_type, $order_no, $order->reference); + $Refs->save($order->trans_type, $order_no, $order->reference, null, $order->fixed_asset); hook_db_postwrite($order, $order->trans_type); commit_transaction(); diff --git a/sales/includes/ui/sales_order_ui.inc b/sales/includes/ui/sales_order_ui.inc index 7b91967b..f2dd4af5 100644 --- a/sales/includes/ui/sales_order_ui.inc +++ b/sales/includes/ui/sales_order_ui.inc @@ -499,7 +499,10 @@ function sales_order_item_controls(&$order, &$rowcounter, $line_no=-1) } else // prepare new line { - sales_items_list_cells(null,'stock_id', null, false, true, true); + if ($order->fixed_asset) + stock_disposable_fa_list_cells(null,'stock_id', null, _('[Select item]'), true, $order->line_items); + else + sales_items_list_cells(null,'stock_id', null, false, true, true); if (list_updated('stock_id')) { $Ajax->activate('price'); $Ajax->activate('units'); @@ -519,7 +522,11 @@ function sales_order_item_controls(&$order, &$rowcounter, $line_no=-1) $_POST['Disc'] = percent_format($order->default_discount * 100); } - qty_cells(null, 'qty', $_POST['qty'], null, null, $dec); + if ($order->fixed_asset) { + label_cell(1, '', 'qty'); + hidden('qty', 1); + } else + qty_cells(null, 'qty', $_POST['qty'], null, null, $dec); if ($order->trans_no!=0) { qty_cell($line_no==-1 ? 0 :$order->line_items[$line_no]->qty_done, false, $dec); @@ -599,7 +606,7 @@ function display_delivery_details(&$order) start_outer_table(TABLESTYLE2, "width='90%'"); table_section(1); - locations_list_row(_("Deliver from Location:"), 'Location', null, false, true); + locations_list_row(_("Deliver from Location:"), 'Location', null, false, true, $order->fixed_asset); if ($order->payment_terms['days_before_due'] < 0) { $Ajax->addUpdate('items_table', 'prep_amount', price_format($order->get_trans_total())); // bind to items_table update diff --git a/sales/sales_order_entry.php b/sales/sales_order_entry.php index aba35ebd..e087804a 100644 --- a/sales/sales_order_entry.php +++ b/sales/sales_order_entry.php @@ -66,9 +66,14 @@ if (isset($_GET['NewDelivery']) && is_numeric($_GET['NewDelivery'])) { } elseif (isset($_GET['NewInvoice']) && is_numeric($_GET['NewInvoice'])) { - $_SESSION['page_title'] = _($help_context = "Direct Sales Invoice"); create_cart(ST_SALESINVOICE, $_GET['NewInvoice']); + if (isset($_GET['FixedAsset'])) { + $_SESSION['page_title'] = _($help_context = "FA Sale"); + $_SESSION['Items']->fixed_asset = true; + } else + $_SESSION['page_title'] = _($help_context = "Direct Sales Invoice"); + } elseif (isset($_GET['ModifyOrderNumber']) && is_numeric($_GET['ModifyOrderNumber'])) { $help_context = 'Modifying Sales Order'; @@ -688,7 +693,10 @@ if (isset($_POST['CancelItemChanges'])) { } //-------------------------------------------------------------------------------- -check_db_has_stock_items(_("There are no inventory items defined in the system.")); +if ($_SESSION['Items']->fixed_asset) + check_db_has_disposable_fixed_assets(_("There are no fixed assets defined in the system.")); +else + check_db_has_stock_items(_("There are no inventory items defined in the system.")); check_db_has_customer_branches(_("There are no customers, or there are no customers with branches. Please define customers and customer branches.")); diff --git a/sql/en_US-demo.sql b/sql/en_US-demo.sql index 4c824481..21dbbbcc 100644 --- a/sql/en_US-demo.sql +++ b/sql/en_US-demo.sql @@ -294,7 +294,7 @@ INSERT INTO `0_chart_master` VALUES ('1205', '', 'Allowance for doubtful account INSERT INTO `0_chart_master` VALUES ('1510', '', 'Inventory', '2', 0); INSERT INTO `0_chart_master` VALUES ('1520', '', 'Stocks of Raw Materials', '2', 0); INSERT INTO `0_chart_master` VALUES ('1530', '', 'Stocks of Work In Progress', '2', 0); -INSERT INTO `0_chart_master` VALUES ('1540', '', 'Stocks of Finsihed Goods', '2', 0); +INSERT INTO `0_chart_master` VALUES ('1540', '', 'Stocks of Finished Goods', '2', 0); INSERT INTO `0_chart_master` VALUES ('1550', '', 'Goods Received Clearing account', '2', 0); INSERT INTO `0_chart_master` VALUES ('1820', '', 'Office Furniture & Equipment', '3', 0); INSERT INTO `0_chart_master` VALUES ('1825', '', 'Accum. Amort. -Furn. & Equip.', '3', 0); @@ -1149,6 +1149,7 @@ CREATE TABLE IF NOT EXISTS `0_locations` ( `fax` varchar(30) NOT NULL DEFAULT '', `email` varchar(100) NOT NULL DEFAULT '', `contact` varchar(30) NOT NULL DEFAULT '', + `fixed_asset` tinyint(1) NOT NULL DEFAULT '0', `inactive` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`loc_code`) ) ENGINE=InnoDB; @@ -1157,7 +1158,7 @@ CREATE TABLE IF NOT EXISTS `0_locations` ( -- Dumping data for table `0_locations` -- -INSERT INTO `0_locations` VALUES ('DEF', 'Default', 'N/A', '', '', '', '', '', 0); +INSERT INTO `0_locations` VALUES ('DEF', 'Default', 'N/A', '', '', '', '', '', 0, 0); -- -------------------------------------------------------- @@ -1745,7 +1746,7 @@ CREATE TABLE IF NOT EXISTS `0_security_roles` ( -- INSERT INTO `0_security_roles` VALUES (1, 'Inquiries', 'Inquiries', '768;2816;3072;3328;5632;5888;8192;8448;10752;11008;13312;15872;16128', '257;258;259;260;513;514;515;516;517;518;519;520;521;522;523;524;525;773;774;2822;3073;3075;3076;3077;3329;3330;3331;3332;3333;3334;3335;5377;5633;5640;5889;5890;5891;7937;7938;7939;7940;8193;8194;8450;8451;10497;10753;11009;11010;11012;13313;13315;15617;15618;15619;15620;15621;15622;15623;15624;15625;15626;15873;15882;16129;16130;16131;16132;775', 0); -INSERT INTO `0_security_roles` VALUES (2, 'System Administrator', 'System Administrator', '256;512;768;2816;3072;3328;5376;5632;5888;7936;8192;8448;10496;10752;11008;13056;13312;15616;15872;16128', '257;258;259;260;513;514;515;516;517;518;519;520;521;522;523;524;525;526;769;770;771;772;773;774;2817;2818;2819;2820;2821;2822;2823;3073;3074;3082;3075;3076;3077;3078;3079;3080;3081;3329;3330;3331;3332;3333;3334;3335;5377;5633;5634;5635;5636;5637;5641;5638;5639;5640;5889;5890;5891;7937;7938;7939;7940;8193;8194;8195;8196;8197;8449;8450;8451;10497;10753;10754;10755;10756;10757;11009;11010;11011;11012;13057;13313;13314;13315;15617;15618;15619;15620;15621;15622;15623;15624;15628;15625;15626;15627;15873;15874;15875;15876;15877;15878;15879;15880;15883;15881;15882;16129;16130;16131;16132;775', 0); +INSERT INTO `0_security_roles` VALUES (2, 'System Administrator', 'System Administrator', '256;512;768;2816;3072;3328;5376;5632;5888;7936;8192;8448;9472;9728;10496;10752;11008;13056;13312;15616;15872;16128', '257;258;259;260;513;514;515;516;517;518;519;520;521;522;523;524;525;526;769;770;771;772;773;774;2817;2818;2819;2820;2821;2822;2823;3073;3074;3082;3075;3076;3077;3078;3079;3080;3081;3329;3330;3331;3332;3333;3334;3335;5377;5633;5634;5635;5636;5637;5641;5638;5639;5640;5889;5890;5891;7937;7938;7939;7940;8193;8194;8195;8196;8197;8449;8450;8451;9217;9218;9220;9473;9474;9475;9476;9729;10497;10753;10754;10755;10756;10757;11009;11010;11011;11012;13057;13313;13314;13315;15617;15618;15619;15620;15621;15622;15623;15624;15628;15625;15626;15627;15873;15874;15875;15876;15877;15878;15879;15880;15883;15881;15882;16129;16130;16131;16132;775', 0); INSERT INTO `0_security_roles` VALUES (3, 'Salesman', 'Salesman', '768;3072;5632;8192;15872', '773;774;3073;3075;3081;5633;8194;15873;775', 0); INSERT INTO `0_security_roles` VALUES (4, 'Stock Manager', 'Stock Manager', '768;2816;3072;3328;5632;5888;8192;8448;10752;11008;13312;15872;16128', '2818;2822;3073;3076;3077;3329;3330;3330;3330;3331;3331;3332;3333;3334;3335;5633;5640;5889;5890;5891;8193;8194;8450;8451;10753;11009;11010;11012;13313;13315;15882;16129;16130;16131;16132;775', 0); INSERT INTO `0_security_roles` VALUES (5, 'Production Manager', 'Production Manager', '512;768;2816;3072;3328;5632;5888;8192;8448;10752;11008;13312;15616;15872;16128', '521;523;524;2818;2819;2820;2821;2822;2823;3073;3074;3076;3077;3078;3079;3080;3081;3329;3330;3330;3330;3331;3331;3332;3333;3334;3335;5633;5640;5640;5889;5890;5891;8193;8194;8196;8197;8450;8451;10753;10755;11009;11010;11012;13313;13315;15617;15619;15620;15621;15624;15624;15876;15877;15880;15882;16129;16130;16131;16132;775', 0); @@ -1834,6 +1835,26 @@ INSERT INTO `0_stock_category` VALUES (1, 'Components', 1, 'each', 'B', '4010', INSERT INTO `0_stock_category` VALUES (2, 'Charges', 1, 'each', 'D', '4010', '5010', '1510', '5040', '1530', 0, 0, 0, 0, 0); INSERT INTO `0_stock_category` VALUES (3, 'Systems', 1, 'each', 'M', '4010', '5010', '1510', '5040', '1530', 0, 0, 0, 0, 0); INSERT INTO `0_stock_category` VALUES (4, 'Services', 1, 'hr', 'D', '4010', '5010', '1510', '5040', '1530', 0, 0, 0, 0, 0); + +-- -------------------------------------------------------- + +-- +-- Structure of table `0_stock_fa_class` ### +-- + +DROP TABLE IF EXISTS `0_stock_fa_class`; +CREATE TABLE `0_stock_fa_class` ( + `fa_class_id` varchar(20) NOT NULL DEFAULT '', + `parent_id` varchar(20) NOT NULL DEFAULT '', + `description` varchar(200) NOT NULL DEFAULT '', + `long_description` tinytext NOT NULL, + `depreciation_method` char(1) NOT NULL DEFAULT 'D', + `depreciation_rate` double NOT NULL DEFAULT '0', + `depreciation_period` tinyint(1) NOT NULL DEFAULT '0', + `inactive` tinyint(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`fa_class_id`) +) ENGINE=InnoDB; + -- -------------------------------------------------------- -- @@ -1865,6 +1886,11 @@ CREATE TABLE IF NOT EXISTS `0_stock_master` ( `no_sale` tinyint(1) NOT NULL DEFAULT '0', `no_purchase` tinyint(1) NOT NULL DEFAULT '0', `editable` tinyint(1) NOT NULL DEFAULT '0', + `depreciation_method` char(1) NOT NULL DEFAULT 'D', + `depreciation_rate` double NOT NULL DEFAULT '0', + `depreciation_start` date NOT NULL DEFAULT '0000-00-00', + `depreciation_date` date NOT NULL DEFAULT '0000-00-00', + `fa_class_id` varchar(20) NOT NULL DEFAULT '', PRIMARY KEY (`stock_id`) ) ENGINE=InnoDB; @@ -1873,12 +1899,12 @@ CREATE TABLE IF NOT EXISTS `0_stock_master` ( -- INSERT INTO `0_stock_master` VALUES -('101', '1', '1', 'iPad Air 2 16GB', '', 'each', 'B', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '200', '0', '0', '0', '0', '0', '0'), -('102', '1', '1', 'iPhone 6 64GB', '', 'each', 'B', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '150', '0', '0', '0', '0', '0', '0'), -('103', '1', '1', 'iPhone Cover Case', '', 'each', 'B', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '10', '0', '0', '0', '0', '0', '0'), -('201', '3', '1', 'AP Surf Set', '', 'each', 'M', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '360', '0', '0', '0', '0', '0', '0'), -('202', '4', '1', 'Maintenance', '', 'hr', 'D', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1'), -('301', '4', '1', 'Support', '', 'hr', 'D', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'); +('101', '1', '1', 'iPad Air 2 16GB', '', 'each', 'B', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '200', '0', '0', '0', '0', '0', '0', 'D', '0', '0000-00-00', '0000-00-00', ''), +('102', '1', '1', 'iPhone 6 64GB', '', 'each', 'B', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '150', '0', '0', '0', '0', '0', '0', 'D', '0', '0000-00-00', '0000-00-00', ''), +('103', '1', '1', 'iPhone Cover Case', '', 'each', 'B', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '10', '0', '0', '0', '0', '0', '0', 'D', '0', '0000-00-00', '0000-00-00', ''), +('201', '3', '1', 'AP Surf Set', '', 'each', 'M', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '360', '0', '0', '0', '0', '0', '0', 'D', '0', '0000-00-00', '0000-00-00', ''), +('202', '4', '1', 'Maintenance', '', 'hr', 'D', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', 'D', '0', '0000-00-00', '0000-00-00', ''), +('301', '4', '1', 'Support', '', 'hr', 'D', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'D', '0', '0000-00-00', '0000-00-00', ''); -- -------------------------------------------------------- @@ -2144,6 +2170,9 @@ INSERT INTO `0_sys_prefs` VALUES ('print_invoice_no','glsetup.sales', 'tinyint', INSERT INTO `0_sys_prefs` VALUES ('allow_negative_prices','glsetup.inventory', 'tinyint', 1, '1'); INSERT INTO `0_sys_prefs` VALUES ('print_item_images_on_quote','glsetup.inventory', 'tinyint', 1, '0'); INSERT INTO `0_sys_prefs` VALUES ('suppress_tax_rates','setup.company', 'tinyint', 1, '0'); +INSERT INTO `0_sys_prefs` VALUES ('default_loss_on_asset_disposal_act', 'glsetup.items', 'varchar', '15', '5660'); +INSERT INTO `0_sys_prefs` VALUES ('depreciation_period', 'glsetup.company', 'tinyint', '1', '1'); + -- -------------------------------------------------------- diff --git a/sql/en_US-new.sql b/sql/en_US-new.sql index f482ee65..7356ecd0 100644 --- a/sql/en_US-new.sql +++ b/sql/en_US-new.sql @@ -978,6 +978,7 @@ CREATE TABLE IF NOT EXISTS `0_locations` ( `fax` varchar(30) NOT NULL default '', `email` varchar(100) NOT NULL default '', `contact` varchar(30) NOT NULL default '', + `fixed_asset` tinyint(1) NOT NULL DEFAULT '0', `inactive` tinyint(1) NOT NULL default '0', PRIMARY KEY (`loc_code`) ) ENGINE=InnoDB; @@ -986,7 +987,7 @@ CREATE TABLE IF NOT EXISTS `0_locations` ( -- Dumping data for table `0_locations` -- -INSERT INTO `0_locations` VALUES ('DEF', 'Default', 'N/A', '', '', '', '', '', 0); +INSERT INTO `0_locations` VALUES ('DEF', 'Default', 'N/A', '', '', '', '', '', 0, 0); -- -------------------------------------------------------- @@ -1503,7 +1504,7 @@ CREATE TABLE IF NOT EXISTS `0_security_roles` ( -- INSERT INTO `0_security_roles` VALUES (1, 'Inquiries', 'Inquiries', '768;2816;3072;3328;5632;5888;8192;8448;10752;11008;13312;15872;16128', '257;258;259;260;513;514;515;516;517;518;519;520;521;522;523;524;525;773;774;2822;3073;3075;3076;3077;3329;3330;3331;3332;3333;3334;3335;5377;5633;5640;5889;5890;5891;7937;7938;7939;7940;8193;8194;8450;8451;10497;10753;11009;11010;11012;13313;13315;15617;15618;15619;15620;15621;15622;15623;15624;15625;15626;15873;15882;16129;16130;16131;16132;775', 0); -INSERT INTO `0_security_roles` VALUES (2, 'System Administrator', 'System Administrator', '256;512;768;2816;3072;3328;5376;5632;5888;7936;8192;8448;10496;10752;11008;13056;13312;15616;15872;16128', '257;258;259;260;513;514;515;516;517;518;519;520;521;522;523;524;525;526;769;770;771;772;773;774;2817;2818;2819;2820;2821;2822;2823;3073;3074;3082;3075;3076;3077;3078;3079;3080;3081;3329;3330;3331;3332;3333;3334;3335;5377;5633;5634;5635;5636;5637;5641;5638;5639;5640;5889;5890;5891;7937;7938;7939;7940;8193;8194;8195;8196;8197;8449;8450;8451;10497;10753;10754;10755;10756;10757;11009;11010;11011;11012;13057;13313;13314;13315;15617;15618;15619;15620;15621;15622;15623;15624;15628;15625;15626;15627;15873;15874;15875;15876;15877;15878;15879;15880;15883;15881;15882;16129;16130;16131;16132;775', 0); +INSERT INTO `0_security_roles` VALUES (2, 'System Administrator', 'System Administrator', '256;512;768;2816;3072;3328;5376;5632;5888;7936;8192;8448;9472;9728;10496;10752;11008;13056;13312;15616;15872;16128', '257;258;259;260;513;514;515;516;517;518;519;520;521;522;523;524;525;526;769;770;771;772;773;774;2817;2818;2819;2820;2821;2822;2823;3073;3074;3082;3075;3076;3077;3078;3079;3080;3081;3329;3330;3331;3332;3333;3334;3335;5377;5633;5634;5635;5636;5637;5641;5638;5639;5640;5889;5890;5891;7937;7938;7939;7940;8193;8194;8195;8196;8197;8449;8450;8451;9217;9218;9220;9473;9474;9475;9476;9729;10497;10753;10754;10755;10756;10757;11009;11010;11011;11012;13057;13313;13314;13315;15617;15618;15619;15620;15621;15622;15623;15624;15628;15625;15626;15627;15873;15874;15875;15876;15877;15878;15879;15880;15883;15881;15882;16129;16130;16131;16132;775', 0); INSERT INTO `0_security_roles` VALUES (3, 'Salesman', 'Salesman', '768;3072;5632;8192;15872', '773;774;3073;3075;3081;5633;8194;15873;775', 0); INSERT INTO `0_security_roles` VALUES (4, 'Stock Manager', 'Stock Manager', '768;2816;3072;3328;5632;5888;8192;8448;10752;11008;13312;15872;16128', '2818;2822;3073;3076;3077;3329;3330;3330;3330;3331;3331;3332;3333;3334;3335;5633;5640;5889;5890;5891;8193;8194;8450;8451;10753;11009;11010;11012;13313;13315;15882;16129;16130;16131;16132;775', 0); INSERT INTO `0_security_roles` VALUES (5, 'Production Manager', 'Production Manager', '512;768;2816;3072;3328;5632;5888;8192;8448;10752;11008;13312;15616;15872;16128', '521;523;524;2818;2819;2820;2821;2822;2823;3073;3074;3076;3077;3078;3079;3080;3081;3329;3330;3330;3330;3331;3331;3332;3333;3334;3335;5633;5640;5640;5889;5890;5891;8193;8194;8196;8197;8450;8451;10753;10755;11009;11010;11012;13313;13315;15617;15619;15620;15621;15624;15624;15876;15877;15880;15882;16129;16130;16131;16132;775', 0); @@ -1592,6 +1593,26 @@ INSERT INTO `0_stock_category` VALUES (1, 'Components', 1, 'each', 'B', '4010', INSERT INTO `0_stock_category` VALUES (2, 'Charges', 1, 'each', 'D', '4010', '5010', '1510', '5040', '1530', 0, 0, 0, 0, 0); INSERT INTO `0_stock_category` VALUES (3, 'Systems', 1, 'each', 'M', '4010', '5010', '1510', '5040', '1530', 0, 0, 0, 0, 0); INSERT INTO `0_stock_category` VALUES (4, 'Services', 1, 'hr', 'D', '4010', '5010', '1510', '5040', '1530', 0, 0, 0, 0, 0); + +-- -------------------------------------------------------- + +-- +-- Structure of table `0_stock_fa_class` ### +-- + +DROP TABLE IF EXISTS `0_stock_fa_class`; +CREATE TABLE `0_stock_fa_class` ( + `fa_class_id` varchar(20) NOT NULL DEFAULT '', + `parent_id` varchar(20) NOT NULL DEFAULT '', + `description` varchar(200) NOT NULL DEFAULT '', + `long_description` tinytext NOT NULL, + `depreciation_method` char(1) NOT NULL DEFAULT 'D', + `depreciation_rate` double NOT NULL DEFAULT '0', + `depreciation_period` tinyint(1) NOT NULL DEFAULT '0', + `inactive` tinyint(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`fa_class_id`) +) ENGINE=InnoDB; + -- -------------------------------------------------------- -- @@ -1623,6 +1644,11 @@ CREATE TABLE IF NOT EXISTS `0_stock_master` ( `no_sale` tinyint(1) NOT NULL default '0', `no_purchase` tinyint(1) NOT NULL default '0', `editable` tinyint(1) NOT NULL default '0', + `depreciation_method` char(1) NOT NULL DEFAULT 'D', + `depreciation_rate` double NOT NULL DEFAULT '0', + `depreciation_start` date NOT NULL DEFAULT '0000-00-00', + `depreciation_date` date NOT NULL DEFAULT '0000-00-00', + `fa_class_id` varchar(20) NOT NULL DEFAULT '', PRIMARY KEY (`stock_id`) ) ENGINE=InnoDB; @@ -1868,6 +1894,8 @@ INSERT INTO `0_sys_prefs` VALUES ('print_invoice_no','glsetup.sales', 'tinyint', INSERT INTO `0_sys_prefs` VALUES ('allow_negative_prices','glsetup.inventory', 'tinyint', 1, '1'); INSERT INTO `0_sys_prefs` VALUES ('print_item_images_on_quote','glsetup.inventory', 'tinyint', 1, '0'); INSERT INTO `0_sys_prefs` VALUES ('suppress_tax_rates','setup.company', 'tinyint', 1, '0'); +INSERT INTO `0_sys_prefs` VALUES ('default_loss_on_asset_disposal_act', 'glsetup.items', 'varchar', '15', '5660'); +INSERT INTO `0_sys_prefs` VALUES ('depreciation_period', 'glsetup.company', 'tinyint', '1', '1'); -- --------------------------------------------------------