[Frontaccounting-cvs_updates] /hg/p/frontaccounting/mercurial: Added get_dispatchable_quantity...
Brought to you by:
frontaccounting,
itronics
From: FrontAccounting <fro...@us...> - 2013-07-16 12:16:24
|
details: http://frontaccounting.hg.sourceforge.net:8000/hgroot/frontaccounting/frontaccounting/hg/p/frontaccounting/mercurial/rev/4a3f3d31c042 changeset: 3281:4a3f3d31c042 user: Maxime Bourget <bm...@gm...> date: Sun Jun 23 21:22:22 2013 +0100 description: Added get_dispatchable_quantity hook. diffstat: includes/hooks.inc | 39 +++++++++++++++++++++++++++++++++++++++ includes/ui/ui_controls.inc | 8 +++++--- sales/customer_delivery.php | 32 +++++++++++++++++--------------- 3 files changed, 61 insertions(+), 18 deletions(-) diffs (124 lines): diff -r 70a97abb4aa9 -r 4a3f3d31c042 includes/hooks.inc --- a/includes/hooks.inc Sun Jun 23 21:14:36 2013 +0100 +++ b/includes/hooks.inc Sun Jun 23 21:22:22 2013 +0100 @@ -190,6 +190,29 @@ { return true; } + + /* + * Returns the quantity allowed to be dispatched for a particular item + * and a status (which can be used to style the row). + * This quantity would be the default value on the delivery note. + * The usual use case for this is when a item is in stock, + * but has been reserved by someone else. + * This allows extensions to implements its own priority algorithm. + * This function is by detail_id and not item in case the item is present + * more than one in the cart. + */ + /* Default behavior check if there is enough quantity on hand and change the css + * class if needed */ + static function default_get_dispatchable_quantity($line_item, $location, $date, $qoh) { + global $SysPrefs; + + if ($SysPrefs->allow_negative_stock() || ($line_item->qty_dispatched <= $qoh)) { + return true; + } + return array($qoh, 'stockmankobg'); + return array($line_item->qty_dispatched, 'stockmankobg'); + } + } /* @@ -415,3 +438,19 @@ { return hook_invoke_last('authenticate', $login, $password); } + + /* + * Returns the quantity allowed to be dispatched for a particular item + * and a "reason" (css classes). + * This quantity would be the default value on the delivery note. + * The usual use case for this is when a item is in stock, + * but has been reserved by someone else. + * This allows extensions to implements its own priority algorithm. + * This function is by detail_id and not item in case the item is present + * more than one in the cart. + * If 'skip' is returned, the line will be skipped and not displayed + */ +function hook_get_dispatchable_quantity($line_item, $location, $date, $qoh) { + $result = hook_invoke_first('get_dispatchable_quantity', $line_item, array($location, $date, $qoh)); + return $result !== null ? $result : hooks::default_get_dispatchable_quantity($line_item, $location, $date, $qoh); +} diff -r 70a97abb4aa9 -r 4a3f3d31c042 includes/ui/ui_controls.inc --- a/includes/ui/ui_controls.inc Sun Jun 23 21:14:36 2013 +0100 +++ b/includes/ui/ui_controls.inc Sun Jun 23 21:22:22 2013 +0100 @@ -306,18 +306,20 @@ //-------------------------------------------------------------------------------------------------- -function alt_table_row_color(&$k) +function alt_table_row_color(&$k, $extra_class=null) { + $classes = $extra_class ? array($extra_class) : array(); if ($k == 1) { - echo "<tr class='oddrow'>\n"; + array_push($classes, 'oddrow'); $k = 0; } else { - echo "<tr class='evenrow'>\n"; + array_push($classes, 'evenrow'); $k++; } + echo "<tr class='".implode(' ', $classes)."'>\n"; } function table_section_title($msg, $colspan=2) diff -r 70a97abb4aa9 -r 4a3f3d31c042 sales/customer_delivery.php --- a/sales/customer_delivery.php Sun Jun 23 21:14:36 2013 +0100 +++ b/sales/customer_delivery.php Sun Jun 23 21:22:22 2013 +0100 @@ -445,23 +445,25 @@ $ln_itm->qty_dispatched = $ln_itm->quantity-$ln_itm->qty_done; } // if it's a non-stock item (eg. service) don't show qoh - $show_qoh = true; - if ($SysPrefs->allow_negative_stock() || !has_stock_holding($ln_itm->mb_flag) || - $ln_itm->qty_dispatched == 0) { - $show_qoh = false; + $row_classes = null; + if (has_stock_holding($ln_itm->mb_flag) && $ln_itm->qty_dispatched) { + // It's a stock : call get_dispatchable_quantity hook to get which quantity to preset in the + // quantity input box. This allows for example a hook to modify the default quantity to what's dispatchable + // (if there is not enough in hand), check at other location or other order people etc ... + // This hook also returns a 'reason' (css classes) which can be used to theme the row. + + $qoh = get_qoh_on_date($ln_itm->stock_id, $_POST['Location'], $_POST['DispatchDate']); + $q_class = hook_get_dispatchable_quantity($ln_itm, $_POST['Location'], $_POST['DispatchDate'], $qoh); + // Skip line if needed + if($q_class === 'skip') continue; + if(is_array($q_class)) { + list($ln_itm->qty_dispatched, $row_classes) = $q_class; + $has_marked = true; + } + } - if ($show_qoh) { - $qoh = get_qoh_on_date($ln_itm->stock_id, $_POST['Location'], $_POST['DispatchDate']); - } - - if ($show_qoh && ($ln_itm->qty_dispatched > $qoh)) { - // oops, we don't have enough of one of the component items - start_row("class='stockmankobg'"); - $has_marked = true; - } else { - alt_table_row_color($k); - } + alt_table_row_color($k, $row_classes); view_stock_status_cell($ln_itm->stock_id); if ($ln_itm->descr_editable) |