'disabled' => false,
'box_hint' => null, // box/selectors hints; null = std see below
'category' => false, // category column name or false
- 'show_inactive' => false // show inactive records.
+ 'show_inactive' => false, // show inactive records.
+ 'editable' => false // false, or length of editable entry field
);
// ------ merge options with defaults ----------
if($options != null)
if (!is_array($opts['where'])) $opts['where'] = array($opts['where']);
$search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
+ // select content filtered by search field:
$search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
+ // select set by select content field
+ $search_button = $search_submit ? $search_submit : ($opts['editable'] ? '_'.$name.'_button' : false);
+
$select_submit = $opts['select_submit'];
$spec_id = $opts['spec_id'];
$spec_option = $opts['spec_option'];
$opts['sel_hint'] = $by_id || $search_box==false ?
'' : _('Press Space tab for search pattern entry');
- if ($opts['box_hint'] === null)
+ if ($opts['box_hint'] === null) // dodaƦ hint dla pustego ****
$opts['box_hint'] = $search_box && $search_submit != false ?
($by_id ? _('Enter code fragment to search or * for all')
: _('Enter description fragment to search or * for all')) :'';
$rel = '';
$limit = '';
- if (isset($_POST['_'.$name.'_update'])) {
+ if (isset($_POST['_'.$name.'_update'])) { // select list or search box change
if ($by_id) $txt = $_POST[$name];
if (!$opts['async'])
if ($search_box) {
// search related sql modifications
- $rel = "rel='$search_box'"; // set relation to list
- if ($opts['search_submit']) {
- if (isset($_POST[$search_submit])) {
- $selected_id = array(); // ignore selected_id while search
- if (!$opts['async'])
- $Ajax->activate('_page_body');
- else
- $Ajax->activate($name);
- }
- if ($txt == '') {
- if ($spec_option === false && $selected_id == array())
- $limit = ' LIMIT 1';
- else
- $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
- }
- else
- if ($txt != '*') {
+ $rel = "rel='$search_box'"; // set relation to list
+ if ($opts['search_submit']) {
+ if (isset($_POST[$search_submit])) {
+ $selected_id = array(); // ignore selected_id while search
+ if (!$opts['async'])
+ $Ajax->activate('_page_body');
+ else
+ $Ajax->activate($name);
+ }
+ if ($txt == '') {
+ if ($spec_option === false && $selected_id == array())
+ $limit = ' LIMIT 1';
+ else
+ $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
+ }
+ else
+ if ($txt != '*') {
- foreach($opts['search'] as $i=> $s)
- $opts['search'][$i] = $s . " LIKE '%{$txt}%'";
- $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
+ foreach($opts['search'] as $i=> $s)
+ $opts['search'][$i] = $s . " LIKE '%{$txt}%'";
+ $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
+ }
}
}
- }
// sql completion
if (count($opts['where'])) {
$where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
$first_id = false;
$found = false;
$lastcat = null;
-//if($name=='stock_id') display_error($sql);
+ $edit = false;
+//if($name=='stock_id') display_notification('<pre>'.print_r($_POST, true).'</pre>');
+//if($name=='stock_id') display_error($search_submit);
if($result = db_query($sql)) {
while ($contact_row = db_fetch($result)) {
$value = $contact_row[0];
$descr = $opts['format']==null ? $contact_row[1] :
call_user_func($opts['format'], $contact_row);
$sel = '';
- if (get_post($search_submit) && ($txt === $value)) {
+ if (get_post($search_button) && ($txt == $value)) {
$selected_id[] = $value;
}
if (in_array($value, $selected_id)) {
$sel = 'selected';
$found = $value;
+ $edit = $opts['editable'] && $contact_row['editable']
+ && ($_POST[$search_box] == $value)
+ ? $descr : false;
+ if ($edit)
+ break; // selected field is editable - abandon list construction
}
// show selected option even if inactive
if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') {
if ($found===false) {
$selected_id = array($first_id);
}
+
$_POST[$name] = $multi ? $selected_id : $selected_id[0];
- if ($by_id && $search_box != false) {
- $txt = $found;
- $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
- }
$selector = "<select ".($multi ? "multiple" : '')
. ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
. "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
. $opts['sel_hint']."' $rel>".$selector."</select>\n";
+ if ($by_id && ($search_box != false || $opts['editable']) ) {
+ // on first display show selector list
+ if (isset($_POST[$search_box]) && $opts['editable'] && $edit) {
+ $selector = "<input type='hidden' name='$name' value='".$_POST[$name]."'>"
+ ."<input type='text' $disabled name='{$name}_text' id='{$name}_text' size='".
+ $opts['editable']."' maxlength='".$opts['max']."' $rel value='$edit'>\n";
+// if ($_POST['_focus'] == $name) {
+ set_focus($name.'_text'); // prevent lost focus
+// }
+ } else if (isset($_POST[$name.'_text']))
+ set_focus($name); // prevent lost focus
+ if (!$opts['editable'])
+ $txt = $found;
+ $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
+ }
+
$Ajax->addUpdate($name, "_{$name}_sel", $selector);
- // because of bug which M$ cannot fix since IE 5.0
- // we must embed whole selector in span tags to enable proper ajax update
+ // span for select list/inut field update
$selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
- if ($select_submit != false) { // if submit on change is used - add select button
+ // if selectable or editable list is used - add select button
+ if ($select_submit != false || $search_button) {
global $_select_button;
// button class selects form reload/ajax selector update
$selector .= sprintf($_select_button, $disabled, user_theme(),
'_'.$name.'_update')."\n";
}
// ------ make combo ----------
-
$edit_entry = '';
if ($search_box != false) {
$edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
.$opts['box_hint']."'"
.(!fallback_mode() && !$by_id ? " style=display:none;":'')
.">\n";
- if ($search_submit != false) {
+ if ($search_submit != false || $opts['editable']) {
global $_search_button;
$edit_entry .= sprintf($_search_button, $disabled, user_theme(),
(fallback_mode() ? '' : 'display:none;'),
- $search_submit)."\n";
+ $search_submit ? $search_submit : "_{$name}_button")."\n";
}
}
default_focus(($search_box && $by_id) ? $search_box : $name);
global $all_items;
// all sales codes
$sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
- i.inactive
+ i.inactive, if(count(*)>1, '0', s.editable) as editable
FROM
".TB_PREF."stock_master s,
".TB_PREF."item_codes i
'size'=>15,
'select_submit'=> $submit_on_change,
'category' => 2,
- 'order' => array('c.description','i.item_code')
+ 'order' => array('c.description','i.item_code'),
+ 'editable' => 30,
+ 'max' => 255
), $opts) );
}
function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
{
return sales_items_list($name, $selected_id, $all_option, $submit_on_change,
- 'kits', array('cells'=>false));
+ 'kits', array('cells'=>false, 'editable' => false));
}
function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
echo "<td>$label</td>\n";
echo "<td>";
echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
- 'local', array('cells'=>false));
+ 'local', array('cells'=>false, 'editable' => false));
echo "</td></tr>";
}
//------------------------------------------------------------------------------------
$items[] = sprintf(_("Activated for '%s'"), $comp['name']);
return array_selector( $name, $value, $items,
array(
- 'spec_option'=> _("Installed on system"),
+ 'spec_option'=> _("Available and/or installed"),
'spec_id' => -1,
'select_submit'=> $submit_on_change,
'async' => true
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)
+ $dimension2_id, $no_sale, $editable)
{
$sql = "UPDATE ".TB_PREF."stock_master SET long_description=".db_escape($long_description).",
description=".db_escape($description).",
dimension_id=".db_escape($dimension_id).",
dimension2_id=".db_escape($dimension2_id).",
tax_type_id=".db_escape($tax_type_id).",
- no_sale=".db_escape($no_sale);
+ no_sale=".db_escape($no_sale).",
+ editable=".db_escape($editable);
if ($units != '')
$sql .= ", units='$units'";
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)
+ $dimension2_id, $no_sale, $editable)
{
$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)
+ adjustment_account, assembly_account, dimension_id, dimension2_id, no_sale, editable)
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).",
.", ".db_escape($cogs_account).",".db_escape($adjustment_account)
.", ".db_escape($assembly_account).", "
.db_escape($dimension_id).", ".db_escape($dimension2_id).","
- .db_escape($no_sale).")";
+ .db_escape($no_sale).","
+ .db_escape($editable).")";
db_query($sql, "The item could not be added");
$_POST['inventory_account'], $_POST['cogs_account'],
$_POST['adjustment_account'], $_POST['assembly_account'],
$_POST['dimension_id'], $_POST['dimension2_id'],
- check_value('no_sale'));
+ check_value('no_sale'), check_value('editable'));
update_record_status($_POST['NewStockID'], $_POST['inactive'],
'stock_master', 'stock_id');
update_record_status($_POST['NewStockID'], $_POST['inactive'],
$_POST['inventory_account'], $_POST['cogs_account'],
$_POST['adjustment_account'], $_POST['assembly_account'],
$_POST['dimension_id'], $_POST['dimension2_id'],
- check_value('no_sale'));
+ check_value('no_sale'), check_value('editable'));
display_notification(_("A new item has been added."));
$_POST['stock_id'] = $_POST['NewStockID'] =
$_POST['description'] = $_POST['long_description'] = '';
- $_POST['no_sale'] = 0;
+ $_POST['no_sale'] = $_POST['editable'] = 0;
set_focus('NewStockID');
}
$Ajax->activate('_page_body');
$_POST['no_sale'] = $myrow['no_sale'];
$_POST['del_image'] = 0;
$_POST['inactive'] = $myrow["inactive"];
+ $_POST['editable'] = $myrow["editable"];
label_row(_("Item Code:"),$_POST['NewStockID']);
hidden('NewStockID', $_POST['NewStockID']);
set_focus('description');
$_POST['dimension_id'] = $category_record["dflt_dim1"];
$_POST['dimension2_id'] = $category_record["dflt_dim2"];
$_POST['no_sale'] = $category_record["dflt_no_sale"];
+ $_POST['editable'] = 0;
+
}
$fresh_item = !isset($_POST['NewStockID']) || $new_item
|| check_usage($_POST['stock_id'],false);
stock_units_list_row(_('Units of Measure:'), 'units', null, $fresh_item);
+check_row(_("Editable description:"), 'editable');
+
+check_row(_("Exclude from sales:"), 'no_sale');
+
+table_section(2);
+
$dim = get_company_pref('use_dimension');
if ($dim >= 1)
{
if ($dim < 2)
hidden('dimension2_id', 0);
-table_section(2);
-
table_section_title(_("GL Accounts"));
gl_all_accounts_list_row(_("Sales Account:"), 'sales_account', $_POST['sales_account']);
if ($check_remove_image)
check_row(_("Delete Image:"), 'del_image');
-check_row(_("Exclude from sales:"), 'no_sale');
-
record_status_list_row(_("Item status:"), 'inactive');
end_outer_table(1);
div_end();
$_POST['stock_id'] = get_global_stock_item();
echo "<center>" . _("Item:"). " ";
-echo sales_items_list('stock_id', $_POST['stock_id'], false, true);
+echo sales_items_list('stock_id', $_POST['stock_id'], false, true, '', array('random_entry' => false));
echo "<hr></center>";
set_global_stock_item($_POST['stock_id']);
save_focus(select);
// submit request if there is submit_on_change option set and
// search field has changed.
+
if (button && (this.value != this.getAttribute('_last'))) {
- JsHttpRequest.request(button);
+ JsHttpRequest.request(button);
} else if(this.className=='combo2') {
this.style.display = 'none';
select.style.display = 'inline';
if(box && s.selectedIndex>=0) {
var opt = s.options[s.selectedIndex];
if(box) {
+ var old = box.value;
box.value = byid ? opt.value : opt.text;
box.setAttribute('_last', box.value);
+ return old != box.value
}
}
}
// signaling we must track selectedIndex in onblur handler.
e.setAttribute('_last', e.selectedIndex);
e.onblur = function() {
- if(this.className=='combo')
- _update_box(this);
- if (this.selectedIndex != this.getAttribute('_last'))
- this.onchange();
+ var box = document.getElementsByName(this.getAttribute('rel'))[0];
+// if(this.className=='combo')
+// _update_box(this);
+ if ((this.selectedIndex != this.getAttribute('_last'))
+ ||(this.className=='combo' && _update_box(this))
+ )
+ this.onchange();
}
e.onchange = function() {
var s = this;
}
}
},
- 'button[aspect=selector], input[aspect=selector]': function(e) {
+ 'button[aspect=selector], button[aspect=abort], input[aspect=selector]': function(e) {
e.onclick = function() {
passBack(this.getAttribute('rel'));
return false;
}
},
+ 'button[aspect=popup]': function(e) {
+ var old = e.onclick
+ e.onclick = function() {
+// this.form.target = '_blank';
+// old();
+// return true;
+ if(_w) _w.close(); // this is really necessary to have window on top in FF2 :/
+ _w = open(document.location+'popup=1',
+ "edit","Scrollbars=0,resizable=0,width=800,height=600, top=50,left=50");
+ if (_w.opener == null)
+ _w.opener = self;
+ // editors._call = key; // store call point for passBack
+// _w.moveTo(50, 50);
+ _w.focus();
+ return false;
+ }
+ },
'select': function(e) {
if(e.onfocus==undefined) {
e.onfocus = function() {
$this->freight_cost = $freight_cost;
}
- function add_to_cart($line_no,$stock_id, $qty, $price, $disc, $qty_done=0, $standard_cost=0, $description=null, $id=0, $src_no=0)
+ function add_to_cart($line_no, $stock_id, $qty, $price, $disc, $qty_done=0, $standard_cost=0, $description=null, $id=0, $src_no=0)
{
- if (isset($stock_id) && $stock_id != "" && isset($qty)/* && $qty > 0*/) {
- $this->line_items[$line_no] = new line_details($stock_id, $qty, $price, $disc,
- $qty_done, $standard_cost, $description, $id, $src_no);
+ $line = new line_details($stock_id, $qty, $price, $disc,
+ $qty_done, $standard_cost, $description, $id, $src_no);
+
+ if ($line->valid) {
+ $this->line_items[$line_no] = $line;
return 1;
- } else {
- // shouldn't come here under normal circumstances
- display_db_error("unexpected - adding an invalid item or null quantity", "", true);
- }
+ } else
+ display_error(_("You have to enter valid stock code or nonempty description"));
return 0;
}
var $qty_dispatched; // quantity selected to process
var $qty_old=0; // quantity dispatched before edition
var $standard_cost;
+ var $descr_editable;
+
+ var $valid; // validation in constructor
function line_details ($stock_id, $qty, $prc, $disc_percent,
$qty_done, $standard_cost, $description, $id=0, $src_no=0 )
$this->src_no = $src_no;
$item_row = get_item($stock_id);
- if ($item_row == null)
- display_db_error("invalid item added to order : $stock_id", "");
-
+ if (!$item_row)
+ return;
+
$this->mb_flag = $item_row["mb_flag"];
$this->units = $item_row["units"];
- if ($description == null)
+ $this->descr_editable = $item_row["editable"];
+ if ($description == null || !$this->descr_editable)
$this->item_description = $item_row["description"];
else
$this->item_description = $description;
//$this->standard_cost = $item_row["material_cost"] + $item_row["labour_cost"] + $item_row["overhead_cost"];
$this->tax_type = $item_row["tax_type_id"];
$this->tax_type_name = $item_row["tax_type_name"];
-
$this->stock_id = $stock_id;
$this->quantity = $qty;
$this->qty_dispatched = $qty;
$this->discount_percent = $disc_percent;
$this->qty_done = $qty_done;
$this->standard_cost = $standard_cost;
+ $this->valid = true;
}
// get unit price as stated on document
include_once($path_to_root . "/includes/manufacturing.inc");
//--------------------------------------------------------------------------------
-function add_to_order(&$order, $new_item, $new_item_qty, $price, $discount)
+function add_to_order(&$order, $new_item, $new_item_qty, $price, $discount, $description='')
{
// calculate item price to sum of kit element prices factor for
// value distribution over all exploded kit items
if (!$item['is_foreign'] && $item['item_code'] != $item['stock_id'])
{ // this is sales kit - recurse
add_to_order($order, $item['stock_id'], $new_item_qty*$item['quantity'],
- $item_price, $discount, $std_price);
+ $item_price, $discount);
}
else
{ // stock item record eventually with foreign code
}
}
$order->add_to_cart (count($order->line_items), $item['stock_id'],
- $new_item_qty*$item['quantity'], $item_price, $discount);
+ $new_item_qty*$item['quantity'], $item_price, $discount, 0,0, $description);
}
}
+
}
//---------------------------------------------------------------------------------
$_POST['qty'] = number_format2($order->line_items[$id]->qty_dispatched, $dec);
$_POST['price'] = price_format($order->line_items[$id]->price);
$_POST['Disc'] = percent_format($order->line_items[$id]->discount_percent*100);
- $_POST['item_description'] = $order->line_items[$id]->item_description;
$units = $order->line_items[$id]->units;
+ $_POST['item_description'] = $order->line_items[$id]->item_description;
hidden('stock_id', $_POST['stock_id']);
label_cell($_POST['stock_id']);
- text_cells(null,'item_description', null, 45, 150);
+ if ($order->line_items[$id]->descr_editable)
+ text_cells(null,'item_description', null, 45, 150);
+ else {
+ hidden('item_description', $_POST['item_description']);
+ label_cell($_POST['item_description']);
+ }
+// } else {
+// sales_items_list_cells(null,'item_description', null, false, true);
+// }
//label_cell($order->line_items[$line_no]->item_description, "nowrap");
$Ajax->activate('items_table');
}
function check_item_data()
{
global $SysPrefs;
-
- if (!check_num('qty', 0) || !check_num('Disc', 0, 100)) {
+
+ if(!get_post('stock_id_text', true)) {
+ display_error( _("Item description cnnot be empty."));
+ set_focus('stock_id_edit');
+ return false;
+ }
+ elseif (!check_num('qty', 0) || !check_num('Disc', 0, 100)) {
display_error( _("The item could not be updated because you are attempting to set the quantity ordered to less than 0, or the discount percent to more than 100."));
set_focus('qty');
return false;
if (!check_item_data()) {
return;
}
- add_to_order($_SESSION['Items'], $_POST['stock_id'], input_num('qty'),
- input_num('price'), input_num('Disc') / 100);
- $_POST['_stock_id_edit'] = $_POST['stock_id'] = "";
+ add_to_order($_SESSION['Items'], get_post('stock_id'), input_num('qty'),
+ input_num('price'), input_num('Disc') / 100, get_post('stock_id_text'));
+
+ unset($_POST['_stock_id_edit'], $_POST['stock_id']);
line_start_focus();
}
}
end_form();
end_page();
-
?>
\ No newline at end of file