X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=includes%2Forder_lines.inc;h=92391f6034458ef3efb3c9447e1562e7dca6a111;hb=7099417ed904d1b154cdd96e20cf70f6659bab01;hp=050fa825c6a9b6828d70782b6ceb4fde114fc16e;hpb=179f6939f643c2ba231adf53f57b55699b152f94;p=order_line_extra.git diff --git a/includes/order_lines.inc b/includes/order_lines.inc index 050fa82..92391f6 100644 --- a/includes/order_lines.inc +++ b/includes/order_lines.inc @@ -1,5 +1,67 @@ and from a string + * generated by the above *_cell function. + * This is usefull to use the result of the function within a pager + * which already include the ... + * However, for function which doesn't return a string + * but echo, we need to capture the output of the echo first. + */ +function start_extract_cell() { + // We need + ob_start(); +} + +function end_extract_cell() { + $content = ob_get_contents(); + ob_end_clean(); + return extract_cell($content); +} + +function extract_cell($td) { + if(preg_match('/\s*(.*)<\/td>\s*/s', $td, $matches)) { + return $matches[1]; + } + else { +print_r('cacou'); + return $td; + } +} + + +function update_extra_order_details() { + if(!isset($_POST['Update']) || $_POST['Update'] != 'Update') return; + +begin_transaction(); + // update in database all field + foreach($_POST['detail'] as $detail_id => $values) { + $set = array(); + if($comment = $values['comment']) array_push($set, " comment='$comment' "); + if(isset($values['required_date'])) { + $required_date = trim($values['required_date']); + if($required_date == "") { + array_push($set," required_date = NULL"); + } else { + $date = date2sql($required_date); + array_push($set," required_date='$date' "); + } + } + + if(!empty($set)) { + $sql = "UPDATE ".TB_PREF."sales_order_details SET ".implode($set,', ')." WHERE id = $detail_id "; + + if(!db_query($sql)) { + display_error('Problem while updating order details. Try again'); + cancel_transaction(); + return; + } + } + + } + + display_notification('Order details updated'); + +} function compute_input_name($row, $field) { $row_id = $row['id']; @@ -11,12 +73,52 @@ function view_link($dummy, $order_no) return get_customer_trans_view_str(ST_SALESORDER, $order_no); } +function item_link($dummy, $stock_id) +{ + return pager_link( _($stock_id), + "/modules/order_line_extra/item_schedule.php?stock_id=" .$stock_id); +} + function order_link($row) { return pager_link( _("Sales Order"), "/sales/sales_order_entry.php?NewQuoteToSalesOrder=" .$row['order_no'], ICON_DOC); } +function customer_link($row) { + return customer_link2($row['debtor_ref'], $row['debtor_no']); +} + +function customer_link2($name, $id) { + return pager_link(_($name), "/modules/order_line_extra/order_lines_view.php?customer_id=${id}"); + +} + +function aggregate_comment($row) { + $comment = $row['order_comment'].";".$row['detail_comment']; + if($comment) { + $comments = array_map('trim', explode(';', $comment)); + $comments = array_filter($comments); + $first = array_shift($comments); + if(count($comments) == 0) + return $first; + else { + $tooltip = implode('
- ', $comments); + return "$first more $tooltip"; + } + } + return ''; +} + +function available_quantity($row, $available) { + $quantity = $row['quantity']; + $class = ''; + if($available== 0) $class = 'limited'; + else if($quantity > $available) $class = 'partial'; + + return "$available"; +} + function input_date_details($row, $date) { $row_id = $row['id']; $name = compute_input_name($row, 'required_date'); @@ -40,19 +142,46 @@ $row_id = $row['id']; "; } -function get_order_details_extra($customer_id) { +function get_order_details_extra($customer_id, $location) { $sql = "SELECT sod.id , so.order_no , stk_code - , quantity - qty_sent + , sod.quantity - qty_sent quantity + , GREATEST(0, LEAST(qoh.quantity - quantity_before, sod.quantity - qty_sent)) + , quantity_before , required_date - , comment + ,comment FROM ".TB_PREF."sales_order_details sod JOIN ".TB_PREF."sales_orders so ON (so.order_no = sod.order_no AND so.trans_type = sod.trans_type + AND so.trans_type = ".ST_SALESORDER." AND so.debtor_no = $customer_id ) - WHERE quantity > qty_sent + JOIN ".TB_PREF."denorm_qoh qoh ON (stock_id = stk_code AND loc_code = '$location') + JOIN ".TB_PREF."denorm_order_details_queue d ON (d.id = sod.id) + WHERE sod.quantity > qty_sent + "; + + return $sql; +} + +function get_order_summary() { + $sql = "SELECT debtor_no, debtor_ref, branch_ref + , min(delivery_date) + , sum(quantity - qty_sent) as quantity + , sum((quantity - qty_sent)*unit_price*(1-discount_percent/100)) as amount + , min(required_date) + , group_concat(distinct comments separator ';') as order_comment + , group_concat(distinct comment separator ';') as detail_comment + FROM ".TB_PREF."sales_order_details sod + JOIN ".TB_PREF."sales_orders so ON (so.order_no = sod.order_no + AND so.trans_type = sod.trans_type + AND so.trans_type = ".ST_SALESORDER." + ) + NATURAL JOIN ".TB_PREF."debtors_master + NATURAL JOIN ".TB_PREF."cust_branch + WHERE quantity > qty_sent AND ".ST_SALESORDER." + GROUP BY debtor_no, branch_code "; return $sql;