Merge branch 'master' into unstable
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 19 Aug 2019 10:41:22 +0000 (12:41 +0200)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 19 Aug 2019 10:41:22 +0000 (12:41 +0200)
35 files changed:
dimensions/inquiry/search_dimensions.php
gl/includes/db/gl_db_trans.inc
gl/includes/db/gl_journal.inc
gl/inquiry/journal_inquiry.php
includes/db/audit_trail_db.inc
includes/ui/ui_lists.inc
includes/ui/ui_view.inc
inventory/adjustments.php
inventory/includes/db/items_adjust_db.inc
inventory/includes/inventory_db.inc
inventory/includes/item_adjustments_ui.inc
js/inserts.js
manufacturing/manage/bom_edit.php
manufacturing/search_work_orders.php
purchasing/includes/db/grn_db.inc
purchasing/includes/db/invoice_db.inc
purchasing/includes/db/po_db.inc
purchasing/includes/supp_trans_class.inc
purchasing/includes/ui/grn_ui.inc
purchasing/includes/ui/invoice_ui.inc
purchasing/includes/ui/po_ui.inc
purchasing/inquiry/po_search.php
purchasing/inquiry/po_search_completed.php
purchasing/inquiry/supplier_inquiry.php
purchasing/manage/suppliers.php
purchasing/supplier_credit.php
purchasing/supplier_invoice.php
purchasing/view/view_grn.php
reporting/includes/class.pdf.inc
reporting/includes/reporting.inc
reporting/rep106.php
sales/includes/db/custalloc_db.inc
sales/includes/ui/sales_order_ui.inc
sales/inquiry/customer_inquiry.php
sales/inquiry/sales_orders_view.php

index 6d23976fb9cb008a7f4c0de8dd0b99d399aca266..4eb25480fe3ef751630139871c0ef1864404a0c6 100644 (file)
@@ -17,6 +17,7 @@ include_once($path_to_root . "/includes/session.inc");
 
 include_once($path_to_root . "/includes/date_functions.inc");
 include_once($path_to_root . "/includes/ui.inc");
+include_once($path_to_root . "/reporting/includes/reporting.inc");
 $js = "";
 if ($SysPrefs->use_popup_windows)
        $js .= get_js_open_window(800, 500);
@@ -117,6 +118,12 @@ function edit_link($row)
                        "/dimensions/dimension_entry.php?trans_no=" . $row["id"], ICON_EDIT);
 }
 
+function prt_link($row)
+{
+       return print_document_link($row['id'], _("Print"), true, ST_DIMENSION, ICON_PRINT);
+}
+
+
 $sql = get_sql_for_search_dimensions($dim, $_POST['FromDate'], $_POST['ToDate'],
        $_POST['OrderNumber'], $_POST['type_'], check_value('OpenOnly'), check_value('OverdueOnly'));
 
@@ -129,7 +136,8 @@ $cols = array(
        _("Due Date") => array('name'=>'due_date', 'type'=>'date', 'ord'=>'asc'), 
        _("Closed") => array('fun'=>'is_closed'),
        _("Balance") => array('type'=>'amount', 'insert'=>true, 'fun'=>'sum_dimension'),
-       array('insert'=>true, 'fun'=>'edit_link')
+       array('insert'=>true, 'fun'=>'edit_link'),
+       array('insert'=>true, 'fun'=>'prt_link')
 );
 
 if ($outstanding_only) {
index feb17f09baa3838bfe80a3ebc01b395ea894cce4..60f0093cfcd0d50304f48cc179f29fae90be4c55 100644 (file)
@@ -599,70 +599,55 @@ function clear_gl_trans($type, $trans_id, $nested=false)
 }
 
 function get_sql_for_journal_inquiry($filter, $from, $to, $ref='', $memo='', $alsoclosed=false,
-                $user_id=null, $contractor_id=null, $dimension=null)
+         $user_id=null)
 {
-
-       $sql = "SELECT  IFNULL(a.gl_seq,0) 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,
-               IF(ISNULL(st.supp_reference), '', st.supp_reference) AS supp_reference,
-               refs.reference,"
-               .($dimension ? " -SUM(IF(dim.dimension in(gl.dimension_id,gl.dimension2_id), gl.amount, 0)) as amount,":" SUM(IF(gl.amount>0, gl.amount,0)) as amount,")
-               ."com.memo_,
-               IF(ISNULL(u.user_id),'',u.user_id) as user_id";
-
-       if ($contractor_id > 0) {
-               $sql.= ", st.supplier_id, dt.debtor_no ";
-       }
-
-       $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"
-                .($dimension ? 
-                " LEFT JOIN (SELECT type, type_no, MAX(IFNULL(dimension_id, dimension2_id)) dimension FROM ".TB_PREF."gl_trans GROUP BY type, type_no) dim 
-                               ON gl.type=dim.type AND gl.type_no=dim.type_no" : '')
-               ." WHERE gl.tran_date >= '" . date2sql($from) . "'
-               AND gl.tran_date <= '" . date2sql($to) . "'
-               AND gl.amount!=0";
-       if ($ref) {
-               $sql .= " AND refs.reference LIKE ". db_escape("%$ref%");
-       }
-       if ($memo) {
-               $sql .= " AND com.memo_ LIKE ". db_escape("%$memo%");
-       }
-       if ($filter != -1) {
-               $sql .= " AND gl.type=".db_escape($filter);
-       }
-       if (!$alsoclosed) {
-               $sql .= " AND gl_seq=0";
-       }
-       else
-               $sql .= " AND NOT ISNULL(a.gl_seq)";
-
-       if ($user_id != null)
-               $sql .= " AND user_id = ".db_escape($user_id);
-
-       if ($contractor_id > 0) {
-               $sql.= " AND (dt.debtor_no =".$contractor_id;
-               $sql.= " OR st.supplier_id =".$contractor_id.") ";
-       }       
-
-       if ($dimension != null)
-               $sql .= " AND dim.dimension = ".db_escape($dimension);
-
-       $sql .= " GROUP BY gl.tran_date, a.gl_seq, gl.type, gl.type_no";
-
-       return $sql;
+    $sql = "SELECT  IFNULL(a.gl_seq,0) as gl_seq,
+        gl.tran_date,
+        gl.type as trans_type,
+        gl.type_no as trans_no,
+        IFNULL(gl.person_id, IFNULL(st.supplier_id, IFNULL(grn.supplier_id, IFNULL(dt.debtor_no, bt.person_id)))) as person_id,
+        IF(ISNULL(st.supp_reference), '', st.supp_reference) AS supp_reference,
+        refs.reference,
+        IF(gl.type=".ST_BANKTRANSFER.",MAX(gl.amount),SUM(IF(gl.amount>0, gl.amount,0))) as amount,
+        com.memo_,
+        IF(ISNULL(u.user_id),'',u.user_id) as user_id,
+        IF(gl.person_id, gl.person_type_id, IF(!ISNULL(st.supplier_id) OR !ISNULL(grn.supplier_id),".  PT_SUPPLIER . "," .  "IF(dt.debtor_no," . PT_CUSTOMER . "," .
+        "IF(bt.person_id != '' AND !ISNULL(bt.person_id), bt.person_type_id, -1)))) as person_type_id
+        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."grn_batch grn ON grn.id=gl.type_no AND gl.type=".ST_SUPPRECEIVE."
+         LEFT JOIN ".TB_PREF."bank_trans bt ON bt.type=gl.type AND bt.trans_no=gl.type_no AND bt.amount!=0
+                 AND (bt.person_id != '' AND !ISNULL(bt.person_id))
+         LEFT JOIN ".TB_PREF."debtor_trans dt ON dt.type=gl.type AND gl.type_no=dt.trans_no
+         LEFT JOIN ".TB_PREF."supp_trans st ON st.type=gl.type AND gl.type_no=st.trans_no
+         WHERE gl.tran_date >= '" . date2sql($from) . "'
+        AND gl.tran_date <= '" . date2sql($to) . "'
+        AND gl.amount!=0";
+    if ($ref) {
+        $sql .= " AND refs.reference LIKE ". db_escape("%$ref%");
+    }
+    if ($memo) {
+        $sql .= " AND com.memo_ LIKE ". db_escape("%$memo%");
+    }
+    if ($filter != -1) {
+        $sql .= " AND gl.type=".db_escape($filter);
+    }
+    if (!$alsoclosed) {
+        $sql .= " AND gl_seq=0";
+    }
+    else
+        $sql .= " AND NOT ISNULL(a.gl_seq)";
+
+    if ($user_id != null)
+        $sql .= " AND user_id = ".db_escape($user_id);
+
+    $sql .= " GROUP BY gl.tran_date, a.gl_seq, gl.type, gl.type_no";
+    return $sql;
 }
index bb2dc5b90dd76e7ca12ea1b851b8b721f443c1d5..c44cb335b3328b8fd15179cecb5259439ed66d5a 100644 (file)
@@ -13,9 +13,8 @@ function add_journal($type, $trans_no, $amount, $tran_date, $currency, $referenc
         $event_date='', $doc_date='')
 {
        $sql = "INSERT INTO ".TB_PREF."journal(
-          `type`,`trans_no`, `amount`, `currency`, `rate`, `reference`, `source_ref`, `tran_date`,
-          `event_date`, `doc_date`)
-          VALUES("
+          `type`,`trans_no`, `amount`, `currency`, `rate`, `reference`, `source_ref`, `tran_date`,`event_date`,`doc_date`)
+         VALUES("
          .db_escape($type).","
          .db_escape($trans_no).","
          .db_escape($amount).","
@@ -23,9 +22,9 @@ function add_journal($type, $trans_no, $amount, $tran_date, $currency, $referenc
          .db_escape($rate).","
          .db_escape($reference).","
          .db_escape($source_ref).","
-         ."'".date2sql($tran_date)."',"
-         ."'".date2sql($event_date)."',"
-         ."'".date2sql($doc_date)."')";
+         ."'".date2sql($tran_date)."','"
+         . ($event_date === '' ? '0000-00-00' : date2sql($event_date))."','"
+         . ($doc_date === '' ? '0000-00-00' : date2sql($doc_date))."')";
 
        return db_query($sql, 'cannot add journal entry');
 }
@@ -39,9 +38,9 @@ function update_journal($type, $trans_no, $amount, $tran_date, $currency, $refer
          ."`rate`=".db_escape($rate).","
          ."`reference`=".db_escape($reference).","
          ."`source_ref`=".db_escape($source_ref).","
-         ."`tran_date`="."'".date2sql($tran_date)."',"
-         ."`event_date`="."'".date2sql($event_date)."',"
-         ."`doc_date`="."'".date2sql($doc_date)."'
+         ."`tran_date`='".date2sql($tran_date)."',"
+         ."`event_date`='".($event_date === '' ? '0000-00-00' : date2sql($event_date))."',"
+         ."`doc_date`='".($doc_date === '' ? '0000-00-00' : date2sql($doc_date))."'
           WHERE `type`=".db_escape($type)." AND " ."`trans_no`=".db_escape($trans_no);
 
        return db_query($sql, 'cannot update journal entry');
index fbd7c06a2efe4a221253774d20732485f9b3cce4..b525374b76345dac05d3f74794b3fbc57c2f3865 100644 (file)
@@ -45,7 +45,7 @@ start_row();
 ref_cells(_("Reference:"), 'Ref', '',null, _('Enter reference fragment or leave empty'));
 
 journal_types_list_cells(_("Type:"), "filterType");
-date_cells(_("From:"), 'FromDate', '', null, 0, -1, 0);
+date_cells(_("From:"), 'FromDate', '', null, -user_transaction_days());
 date_cells(_("To:"), 'ToDate');
 
 end_row();
@@ -71,6 +71,11 @@ function systype_name($dummy, $type)
        return $systypes_array[$type];
 }
 
+function person_link($row) 
+{
+    return payment_person_name($row["person_type_id"],$row["person_id"]);
+}
+
 function view_link($row) 
 {
        return get_trans_view_str($row["trans_type"], $row["trans_no"]);
@@ -108,7 +113,7 @@ $cols = array(
        _("Date") =>array('name'=>'tran_date','type'=>'date','ord'=>'desc'),
        _("Type") => array('fun'=>'systype_name'), 
        _("Trans #") => array('fun'=>'view_link'), 
-       _("Counterparty") => array('ord' => ''),
+       _("Counterparty") => array('fun' => 'person_link'),
        _("Supplier's Reference") => 'skip',
        _("Reference"), 
        _("Amount") => array('type'=>'amount'),
index feb85a991f744b6ed3facf54fd4fffaff18d7964..c142abdb9fbad020fb1ccaa1e5dce447d15552ce 100644 (file)
@@ -12,6 +12,7 @@
 
 function add_audit_trail($trans_type, $trans_no, $trans_date, $descr='')
 {
+       $descr = substr($descr, 0, 60);
        begin_transaction();
 
        $date = date2sql($trans_date);
@@ -26,7 +27,7 @@ function add_audit_trail($trans_type, $trans_no, $trans_date, $descr='')
        // to avoid need for subqueries (not existing in MySQL 3) all over the code
        $sql = "UPDATE ".TB_PREF."audit_trail audit LEFT JOIN ".TB_PREF."fiscal_year year ON year.begin<='$date' AND year.end>='$date'
                SET audit.gl_seq = IF(audit.id=".db_insert_id().", 0, NULL),"
-               ."audit.fiscal_year=year.id, stamp=CURRENT_TIMESTAMP"
+               ."audit.fiscal_year=year.id"
                . " WHERE type=".db_escape($trans_type)." AND trans_no="
                . db_escape($trans_no);
 
index f0c65e08417e3061b0f4fcf1867b0b467c069eb3..55ef6777d5d004a40c4fbcfa8c82cadde687713c 100644 (file)
@@ -365,7 +365,7 @@ $opts = array(              // default options
                $selector .= ' '.$opts['editlink'];
 
        if ($search_box && $opts['cells'])
-               $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector$img</td>";
+               $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td nowrap>$selector$img</td>";
        else
                $str = $edit_entry.$selector.$img;
        return $str;
@@ -944,7 +944,7 @@ function sales_items_list_cells($label, $name, $selected_id=null, $all_option=fa
        if ($label != null)
                echo "<td>$label</td>\n";
        echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
-               '', array('cells'=>true));
+               '', array('cells'=>true, 'max'=>50)); // maximum is set to 50 and not default 255.
 }
 
 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
index 35363f896bd519e2792499ab0e241f37e9589401..59fa6888b0f256c6ff63f2cc8dd59d588c643f49 100644 (file)
@@ -270,7 +270,7 @@ function check_ui_refresh($name=null)
 // When there is no exrate for today, 
 // gets it form ECB and stores in local database.
 //
-function exchange_rate_display($from_currency, $to_currency, $date_, $force_edit=false)
+function exchange_rate_display($from_currency=null, $to_currency=null, $date_, $force_edit=false)
 {
     global $Ajax, $SysPrefs;
 
@@ -281,6 +281,12 @@ function exchange_rate_display($from_currency, $to_currency, $date_, $force_edit
                $rate = input_num('_ex_rate');
                if (check_ui_refresh() || !$rate) { // readonly or ui context changed
                        $comp_currency = get_company_currency();
+
+                       if (!isset($from_currency))
+                               $from_currency = $comp_currency;
+                       if (!isset($to_currency))
+                               $to_currency = $comp_currency;
+
                        if ($from_currency == $comp_currency)
                                $currency = $to_currency;
                        else
index ba5dcf49fbcdbe83e1d9ac1f301b07222d78be4a..fe72039205790b54bec9e627f23c44a552407daa 100644 (file)
@@ -210,13 +210,16 @@ $id = find_submit('Delete');
 if ($id != -1)
        handle_delete_item($id);
 
-if (isset($_POST['AddItem']) && check_item_data())
+if (isset($_POST['AddItem']) && check_item_data()) {
        handle_new_item();
-
-if (isset($_POST['UpdateItem']) && check_item_data())
+       unset($_POST['selected_id']);
+}
+if (isset($_POST['UpdateItem']) && check_item_data()) {
        handle_update_item();
-
+       unset($_POST['selected_id']);
+}
 if (isset($_POST['CancelItemChanges'])) {
+       unset($_POST['selected_id']);
        line_start_focus();
 }
 //-----------------------------------------------------------------------------------------------
index 605206cbd97bf9569617575f839f3b5132cd1deb..9a45e0f7d02c077a10157a07d1e0a8ca7c02b33f 100644 (file)
@@ -33,10 +33,10 @@ function add_stock_adjustment($items, $location, $date_, $reference, $memo_)
        foreach ($items as $line_item)
        {
 
-               if ($SysPrefs->loc_notification() == 1 && $line_item->qty < 0)
+               if ($SysPrefs->loc_notification() == 1 && $line_item->quantity < 0)
                {
-                       $chg = $line; $chg->qty = -$chg->qty;   // calculate_reorder_level expect positive qty
-                       $loc = calculate_reorder_level($location, $line_item, $st_ids, $st_names, $st_num, $st_reorder); 
+                       $chg = $line_item; $chg->quantity= -$chg->quantity;     // calculate_reorder_level expect positive qty
+                       $loc = calculate_reorder_level($location, $chg, $st_ids, $st_names, $st_num, $st_reorder); 
                }
 
                add_stock_adjustment_item($adj_id, $line_item->stock_id, $location, $date_, $reference,
index 901ddcfd9dae68c561c10c65f9135fce4e2c7c51..7b672fae8a3609d517ab1d659e9988b4e3e0bb6d 100644 (file)
@@ -34,14 +34,16 @@ function get_stock_movements($stock_id, $StockLocation,     $BeforeDate, $AfterDate)
 {
        $before_date = date2sql($BeforeDate);
        $after_date = date2sql($AfterDate);
-       $sql = "SELECT move.*, IF(ISNULL(supplier.supplier_id), debtor.name, supplier.supp_name) name";
+       // PO Delivery and Customer Credit Notes references should be saved in stock moves reference in 2.5
+       $sql = "SELECT move.*, IF(ISNULL(supplier.supplier_id), debtor.name, supplier.supp_name) name,
+               IF(move.type=".ST_SUPPRECEIVE.", grn.reference, IF(move.type=".ST_CUSTCREDIT.", cust_trans.reference, move.reference)) reference";
 
        if(!$StockLocation) {
                 $sql .= ", move.loc_code";
        }
        $sql.=    " FROM ".TB_PREF."stock_moves move
                                LEFT JOIN ".TB_PREF."supp_trans credit ON credit.trans_no=move.trans_no AND credit.type=move.type
-                               LEFT JOIN ".TB_PREF."grn_batch grn ON grn.id=move.trans_no AND 25=move.type
+                               LEFT JOIN ".TB_PREF."grn_batch grn ON grn.id=move.trans_no AND move.type=".ST_SUPPRECEIVE."
                                LEFT JOIN ".TB_PREF."suppliers supplier ON IFNULL(grn.supplier_id, credit.supplier_id)=supplier.supplier_id
                                LEFT JOIN ".TB_PREF."debtor_trans cust_trans ON cust_trans.trans_no=move.trans_no AND cust_trans.type=move.type
                                LEFT JOIN ".TB_PREF."debtors_master debtor ON cust_trans.debtor_no=debtor.debtor_no
index 66223fb4a4d20b482b4d219db5d3799908666294..1e15ff950028494475aeda1843fc2a6a21c518e4 100644 (file)
@@ -60,14 +60,13 @@ function display_adjustment_items($title, &$order)
                _("Unit"), _("Unit Cost"), _("Total"), "");
                if ( count($order->line_items)) $th[] = '';
        }
-       if ( count($order->line_items)) $th[] = '';
 
        table_header($th);
        $total = 0;
        $k = 0;  //row colour counter
 
        $low_stock = $order->check_qoh($_POST['StockLocation'], $_POST['AdjDate']);
-       $id = find_submit('Edit');
+       $id = get_post('selected_id', find_submit('Edit'));
        foreach ($order->line_items as $line_no=>$stock_item)
        {
 
@@ -97,9 +96,16 @@ function display_adjustment_items($title, &$order)
                                amount_cell($stock_item->standard_cost * $stock_item->quantity);
 
                if (!$order->fixed_asset) {
-                       edit_button_cell("Edit$line_no", _("Edit"),     _('Edit document line'));
+                       if ($id == -1)
+                               edit_button_cell("Edit$line_no", _("Edit"),     _('Edit document line'));
+                       else
+                               label_cell('');
                }
-                       delete_button_cell("Delete$line_no", _("Delete"), _('Remove line from document'));
+               if ($id == -1)
+                               delete_button_cell("Delete$line_no", _("Delete"), _('Remove line from document'));
+               else
+                       label_cell('');
+                       
                        end_row();
                }
                else
@@ -114,6 +120,9 @@ function display_adjustment_items($title, &$order)
        label_row(_("Total"), number_format2($total,user_price_dec()), "align=right colspan=5", "align=right", 2);
 
     end_table();
+
+       if ($id != -1)
+           hidden('selected_id', $id);
        if ($low_stock)
                display_note(_("Marked items have insufficient quantities in stock as on day of adjustment."), 0, 1, "class='stockmankofg'");
        div_end();
@@ -127,19 +136,20 @@ function adjustment_edit_item_controls(&$order, $line_no=-1)
        start_row();
 
        $dec2 = 0;
-       $id = find_submit('Edit');
-       if ($line_no != -1 && $line_no == $id)
-       {
-               $_POST['stock_id'] = $order->line_items[$id]->stock_id;
-               $_POST['qty'] = qty_format($order->line_items[$id]->quantity, 
-                       $order->line_items[$id]->stock_id, $dec);
-               //$_POST['std_cost'] = price_format($order->line_items[$id]->standard_cost);
-               $_POST['std_cost'] = price_decimal_format($order->line_items[$id]->standard_cost, $dec2);
-               $_POST['units'] = $order->line_items[$id]->units;
 
+       if ($line_no != -1)
+       {
+               if (find_submit('Edit') != -1) {
+                       $_POST['stock_id'] = $order->line_items[$line_no]->stock_id;
+                       $_POST['qty'] = qty_format($order->line_items[$line_no]->quantity, 
+                               $order->line_items[$line_no]->stock_id, $dec);
+               //$_POST['std_cost'] = price_format($order->line_items[$line_no]->standard_cost);
+                       $_POST['std_cost'] = price_decimal_format($order->line_items[$line_no]->standard_cost, $dec2);
+               }
+               $_POST['units'] = $order->line_items[$line_no]->units;
                hidden('stock_id', $_POST['stock_id']);
                label_cell($_POST['stock_id']);
-               label_cell($order->line_items[$id]->item_description, 'nowrap');
+               label_cell($order->line_items[$line_no]->item_description, 'nowrap');
            $Ajax->activate('items_table');
        }
        else
@@ -150,49 +160,53 @@ function adjustment_edit_item_controls(&$order, $line_no=-1)
                        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');
+                       $Ajax->activate('items_table');
                }
 
-       $item_info = get_item_edit_info($_POST['stock_id']);
+       }
+
+       $item_info = get_item_edit_info(get_post('stock_id'));
+       if ($item_info) {
                $dec = $item_info['decimals'];
-               $_POST['qty'] = number_format2(0, $dec);
                $_POST['std_cost'] = price_decimal_format($item_info["material_cost"], $dec2);
                $_POST['units'] = $item_info["units"];
-       }
-
+       } else
+               $dec = 0;
        if ($order->fixed_asset) {
                hidden('qty', -1);
                qty_cell(1, false, 0);
        } else
-               qty_cells(null, 'qty', $_POST['qty'], null, null, $dec);
+               label_cell( text_input('qty', get_post('qty', '0'), 15, 15, '',  'class="amount active" dec='.$dec), "nowrap align=right");
 
-       label_cell($_POST['units'], '', 'units');
+       label_cell(get_post('units'), '', 'units');
 
        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_purchase_value($_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);
+               if (get_post('_qty_changed')) {
+                       $Ajax->activate('items_table');
+                       set_focus(input_num('qty') >= 0 ? 'std_cost' : 'AddItem');
+               }
+               if (input_num('qty') >= 0)
+                   amount_cells(null, 'std_cost', null, null, null, $dec);
+               else {
+                   hidden('std_cost');
+                       label_cell($_POST['std_cost'], "nowrap align=right");
+               }
                label_cell("&nbsp;");
        }
 
-       if ($id != -1)
+       if ($line_no != -1)
        {
                button_cell('UpdateItem', _("Update"),
                                _('Confirm changes'), ICON_UPDATE);
                button_cell('CancelItemChanges', _("Cancel"),
                                _('Cancel changes'), ICON_CANCEL);
                hidden('LineNo', $line_no);
-               set_focus('qty');
+               set_focus('qty');
        }
        else
        {
index 773fc8f4f7f1b8b8a37c82e20bbe1938cef19602..40337e7a94a68e7bc2df0c3fa0bfc02e36c289a2 100644 (file)
@@ -346,11 +346,18 @@ var inserts = {
                                return false;
                        }
        },
-    '.amount': function(e) {
-               if(e.onblur==undefined) {
+       '.amount': function(e) {
+               if (e.onblur == undefined) {
+                 e.setAttribute('_last_val', e.value);
                  e.onblur = function() {
                        var dec = this.getAttribute("dec");
-                       price_format(this.name, get_amount(this.name), dec);
+                       var val = this.getAttribute('_last_val');
+                       if (val != get_amount(this.name)) {
+                               this.setAttribute('_last_val', get_amount(this.name));
+                               price_format(this.name, get_amount(this.name), dec);
+                               if (e.className.match(/\bactive\b/))
+                                       JsHttpRequest.request('_'+this.name+'_changed', this.form);
+                       }
                  };
                }
        },
index 35230ddb5ab0a70ccb489d1e7be0adbb0d1ee8a2..697629bcf923aad5f574ecd5a515e8a6b84115eb 100644 (file)
@@ -45,9 +45,10 @@ function display_bom_items($selected_parent)
        table_header($th);
 
        $k = 0;
+       $found = false;
        while ($myrow = db_fetch($result))
        {
-
+               $found = true;
                alt_table_row_color($k);
 
                label_cell($myrow["component"]);
@@ -62,9 +63,29 @@ function display_bom_items($selected_parent)
 
        } //END WHILE LIST LOOP
        end_table();
+       
+       if ($found) {
+               start_table(TABLESTYLE, "width='60%'");
+               stock_manufactured_items_list_row(_("Copy BOM to another manufacturable item"), 'new_stock_id', $selected_parent, false, true);
+               end_table();
+       }
+
        div_end();
 }
 
+function copy_bom_items($stock_id, $new_stock_id)
+{
+       $result = get_bom($stock_id);
+       while ($myrow = db_fetch($result))
+       {
+               $_POST['component'] = $myrow["component"];
+               $_POST['loc_code'] = $myrow["loc_code"];
+               $_POST['workcentre_added'] = $myrow["workcentre_added"];
+               $_POST['quantity'] = $myrow["quantity"];
+               on_submit($new_stock_id, -1);
+       }
+}
 //--------------------------------------------------------------------------------------------------
 
 function on_submit($selected_parent, $selected_component=-1)
@@ -135,6 +156,14 @@ if ($Mode == 'RESET')
 
 //--------------------------------------------------------------------------------------------------
 
+if (list_updated('new_stock_id')) {
+       copy_bom_items($_POST['stock_id'], $_POST['new_stock_id']);
+       $item = get_item($_POST['new_stock_id']);
+       $_POST['stock_id'] = $_POST['new_stock_id'];
+       $Ajax->activate('_page_body');
+       display_notification(_("BOM copied to ") . $item['description']);
+}
+
 start_form();
 
 start_form(false, true);
index 1c407b6487eb81087249a0dcd10bdcd2280db564..4762881ff7f2dbc1e818a23bb2c3703870f5549d 100644 (file)
@@ -16,6 +16,8 @@ include_once($path_to_root . "/includes/session.inc");
 
 include_once($path_to_root . "/includes/date_functions.inc");
 include_once($path_to_root . "/manufacturing/includes/manufacturing_ui.inc");
+include_once($path_to_root . "/reporting/includes/reporting.inc");
+
 $js = "";
 if ($SysPrefs->use_popup_windows)
        $js .= get_js_open_window(800, 500);
@@ -145,6 +147,11 @@ function view_gl_link($row)
        return get_gl_view_str(ST_WORKORDER, $row['id']);
 }
 
+function prt_link($row)
+{
+       return print_document_link($row['id'], _("Print"), true, ST_WORKORDER, ICON_PRINT);
+}
+
 function dec_amount($row, $amount)
 {
        return number_format2($amount, $row['decimals']);
@@ -163,11 +170,12 @@ $cols = array(
        _("Manufactured") => array('fun'=>'dec_amount', 'align'=>'right'),
        _("Date") => array('name'=>'date_', 'type'=>'date', 'ord'=>'desc'), 
        _("Required By") => array('type'=>'date', 'ord'=>''),
+       array('insert'=>true, 'fun'=> 'view_gl_link'),
        array('insert'=>true, 'fun'=> 'edit_link'),
        array('insert'=>true, 'fun'=> 'release_link'),
        array('insert'=>true, 'fun'=> 'costs_link'),
        array('insert'=>true, 'fun'=> 'produce_link'),
-       array('insert'=>true, 'fun'=> 'view_gl_link')
+       array('insert'=>true, 'fun'=> 'prt_link')
 );
 
 $table =& new_db_pager('orders_tbl', $sql, $cols);
index 065b2c7d04fa0162df19529e402d9282c09d5fa4..d3cee3398e5a1e45c872df53caa53fc24579e9be 100644 (file)
@@ -255,7 +255,7 @@ function set_grn_item_credited(&$entered_grn, $supplier, $transno, $date)
 function get_grn_items($grn_batch_id=0, $supplier_id="", $outstanding_only=false,
        $is_invoiced_only=false, $invoice_no=0, $begin="", $end="")
 {
-    $sql = "SELECT grn.*, grn_item.*,
+    $sql = "SELECT grn.*, grn_item.*, po_item.delivery_date as req_del_date,
                grn_item.quantity_inv".($invoice_no ? "-invoice_item.quantity" : '')."  quantity_inv,
        po_item.unit_price,
        po_item.act_price,
@@ -346,7 +346,7 @@ function read_grn_items_to_order($grn_batch, &$order)
 
                        $order->add_to_order($order->lines_on_order, $myrow["item_code"],
                                $myrow["qty_recd"],$myrow["description"], $myrow["unit_price"],$units,
-                               sql2date($myrow["delivery_date"]), $myrow["quantity_inv"],
+                               sql2date($myrow["req_del_date"]), $myrow["quantity_inv"],
                                $myrow["qty_recd"]);
 
                        $order->line_items[$order->lines_on_order-1]->po_detail_rec = $myrow["po_detail_item"];
index 1605024261687c0ee5b4e45c0a4fdf8bbf2a4b61..0a7f360b647af2638404c59b4d0347aded6f0de5 100644 (file)
@@ -19,7 +19,7 @@ function read_supplier_details_to_trans(&$supp_trans, $supplier_id)
        $sql = "SELECT supp.supp_name, terms.terms, terms.days_before_due, supp.dimension_id, supp.dimension2_id,
                terms.day_in_following_month, supp.tax_included,
                supp.tax_group_id, tax_group.name AS tax_group_name,
-               supp.credit_limit - Sum((ov_amount + ov_gst + ov_discount)) as cur_credit
+               supp.credit_limit - Sum((ov_amount + ov_gst + ov_discount)) as cur_credit, curr_code
                FROM ".TB_PREF."suppliers supp LEFT JOIN "
                        .TB_PREF."supp_trans trans ON supp.supplier_id = trans.supplier_id, "
                        .TB_PREF."payment_terms terms, "
@@ -56,6 +56,7 @@ function read_supplier_details_to_trans(&$supp_trans, $supplier_id)
        $supp_trans->tax_group_id = $myrow['tax_group_id'];
        $supp_trans->dimension = $myrow['dimension_id'];
        $supp_trans->dimension2 = $myrow['dimension2_id'];
+       $supp_trans->currency = $myrow['curr_code'];
  
 }
 
@@ -142,7 +143,7 @@ function add_supp_invoice(&$supp_trans)
        } else
                $allocs = get_po_prepayments($supp_trans);
 
-       add_new_exchange_rate($supplier['curr_code'], $supp_trans->tran_date, $supp_trans->ex_rate);
+       add_new_exchange_rate($supp_trans->currency, $supp_trans->tran_date, $supp_trans->ex_rate);
 
     foreach ($taxes as $n => $taxitem)
     {
@@ -170,7 +171,7 @@ function add_supp_invoice(&$supp_trans)
        }
 
     $date_ = $supp_trans->tran_date;
-       $ex_rate = get_exchange_rate_from_home_currency($supplier['curr_code'], $date_);
+       $ex_rate = get_exchange_rate_from_home_currency($supp_trans->currency, $date_);
 
     /*First insert the invoice into the supp_trans table*/
        $invoice_id = write_supp_trans($trans_type, 0, $supp_trans->supplier_id, $date_, $supp_trans->due_date,
@@ -304,7 +305,7 @@ function add_supp_invoice(&$supp_trans)
                                        $dim, $dim2, $taxfree_line, $supp_trans->supplier_id);
                        else
                        {
-                               $ex_rate = get_exchange_rate_from_home_currency($supplier['curr_code'], $old_date);
+                               $ex_rate = get_exchange_rate_from_home_currency($supp_trans->currency, $old_date);
                                $old_value = get_tax_free_price_for_item($entered_grn->item_code, $entered_grn->this_quantity_inv * $old_price, 
                                          $supp_trans->tax_group_id, $supp_trans->tax_included);
 
@@ -448,7 +449,7 @@ function get_tax_overrides($trans_type, $trans_no)
 
 function read_supp_invoice($trans_no, $trans_type, &$supp_trans)
 {
-       $sql = "SELECT trans.*, supp_name, dimension_id, dimension2_id
+       $sql = "SELECT trans.*, supp_name, dimension_id, dimension2_id, curr_code
                FROM ".TB_PREF."supp_trans trans,"
                        .TB_PREF."suppliers sup
                WHERE trans_no = ".db_escape($trans_no)." AND type = ".db_escape($trans_type)."
@@ -473,6 +474,7 @@ function read_supp_invoice($trans_no, $trans_type, &$supp_trans)
                $supp_trans->tax_included = $trans_row["tax_included"];
                $supp_trans->dimension = $trans_row["dimension_id"];
                $supp_trans->dimension2 = $trans_row["dimension2_id"];
+               $supp_trans->currency = $trans_row["curr_code"];
 
                $id = $trans_row["trans_no"];
 
index 0afbe1626292c98bac2236a586afdabf2948e650..a904c2ff4b396cf47135975c05b31b6362a7dd61 100644 (file)
@@ -294,6 +294,8 @@ function get_sql_for_po_search_completed($from, $to, $supplier_id=ALL_TEXT, $loc
                porder.ord_date, 
                supplier.curr_code, 
                Sum(line.unit_price*line.quantity_ordered) AS OrderValue,
+               Sum(line.delivery_date < '". date2sql(Today()) ."'
+               AND (line.quantity_ordered > line.quantity_received)) As OverDue,
                porder.into_stock_location,
                chk.isopen
                FROM ".TB_PREF."purch_orders as porder
index 8a70e41488f47b4565511838be523cf5f42c8fe4..be9ec00d3760477bee42b9102f76ee2a4248f935 100644 (file)
@@ -74,7 +74,7 @@ class supp_trans
 
        function add_grn_to_trans($grn_item_id, $po_detail_item, $item_code, $item_description, 
                $qty_recd, $prev_quantity_inv, $this_quantity_inv, $order_price, $chg_price, 
-               $std_cost_unit, $gl_code)
+               $std_cost_unit=null, $gl_code='')
        {
                $this->grn_items[$grn_item_id] = new grn_item($grn_item_id, $po_detail_item, 
                        $item_code, $item_description, $qty_recd, $prev_quantity_inv, $this_quantity_inv, 
index a0ab2c4822827b6c782e8d4e5eca198a8dd8841d..1112ce077f1e0cadcd72a137be1826c5f30bf25f 100644 (file)
@@ -25,7 +25,7 @@ function display_grn_summary(&$po)
     label_cells(_("For Purchase Order"), get_trans_view_str(ST_PURCHORDER, $po->order_no),
        "class='tableheader2'");
 
-       label_cells(_("Ordered On"), $po->orig_order_date, "class='tableheader2'");
+       label_cells(_("Delivery Date"), $po->orig_order_date, "class='tableheader2'"); // FIXME: delivery date
        end_row();
 
        start_row();
index d6258d281b5c180c842686f36d5a53a82d7f01d3..fc779227793c7c0497f8a73933df2665fca5de8a 100644 (file)
@@ -146,14 +146,12 @@ function invoice_header(&$supp_trans)
 
        set_global_supplier($_POST['supplier_id']);
 
-       $supplier_currency = get_supplier_currency($supp_trans->supplier_id);
-
        $company_currency = get_company_currency();
 
-       if ($supplier_currency != $company_currency)
+       if ($supp_trans->currency != $company_currency)
        {
-        label_row(_("Supplier's Currency:"), "<b>" . $supplier_currency . "</b>");
-               exchange_rate_display($company_currency, $supplier_currency, $_POST['tran_date']);
+        label_row(_("Supplier's Currency:"), "<b>" . $supp_trans->currency . "</b>");
+               exchange_rate_display($company_currency, $supp_trans->currency, $_POST['tran_date']);
        }
 
        label_row(_("Tax Group:"), $supp_trans->tax_description);
@@ -393,7 +391,6 @@ function display_grn_items_for_selection(&$supp_trans, $k)
                hidden('item_description'.$n, $myrow["description"]);
                hidden('prev_quantity_inv'.$n, $myrow['quantity_inv']);
                hidden('order_price'.$n, $myrow['unit_price']);
-               hidden('std_cost_unit'.$n, $myrow['std_cost_unit']);
                hidden('po_detail_item'.$n, $myrow['po_detail_item']);
                label_cell(get_trans_view_str(ST_PURCHORDER, $myrow["purch_order_no"]), "nowrap align='right'");
             label_cell($myrow["item_code"]);
@@ -528,12 +525,12 @@ function display_grn_items(&$supp_trans, $mode=0)
                alt_table_row_color($k);
 
                        $grn_batch = get_grn_batch_from_item($entered_grn->id);
-               label_cell(get_trans_view_str(ST_SUPPRECEIVE, $grn_batch));
+               label_cell(get_trans_view_str(ST_SUPPRECEIVE, $grn_batch), "nowrap align='right'");
                if ($mode == 1)
                {
 //                             label_cell($entered_grn->id);
                                $row = get_grn_batch($grn_batch);
-                               label_cell(get_trans_view_str(ST_PURCHORDER, $row["purch_order_no"])); // PO
+                               label_cell(get_trans_view_str(ST_PURCHORDER, $row["purch_order_no"]), "nowrap align='right'"); // PO
                        }       
                        label_cell($entered_grn->item_code);
                        label_cell($entered_grn->item_description);
index 6d74bcbe43572f1a803c7bcd734d11065c22cd39..b71359576c1f5b06759d925a69c22e7489bff8cc 100644 (file)
@@ -166,7 +166,7 @@ function display_po_header(&$order)
        if ($order->trans_type==ST_SUPPINVOICE)
                date_row(_("Due Date:"), 'due_date', '', false, 0, 0, 0, null, true);
 
-       text_row(_("Supplier's Reference:"), 'supp_ref', null, 16, 15);
+       text_row(_("Supplier's Reference:"), 'supp_ref', null, 20, 60);
 
        if (get_company_pref('use_dimension'))
                dimensions_list_row(_('Dimension').':', 'dimension', null, true, _('Default'), false, 1);
index 9e77d7104d038d8379f93ec974a29f5febaa30cb..efd650752943570cc799e37c4fe2154021840b2d 100644 (file)
@@ -123,8 +123,8 @@ $cols = array(
                _("Currency") => array('align'=>'center'), 
                _("Order Total") => 'amount',
                array('insert'=>true, 'fun'=>'edit_link'),
-               array('insert'=>true, 'fun'=>'prt_link'),
-               array('insert'=>true, 'fun'=>'receive_link')
+               array('insert'=>true, 'fun'=>'receive_link'),
+               array('insert'=>true, 'fun'=>'prt_link')
 );
 
 if (get_post('StockLocation') != ALL_TEXT) {
index 8c939aba7717cc474867caf8750512813b3b150f..4046424e69f39b5b0a0d504bdd9a97092800f1dd 100644 (file)
@@ -38,6 +38,15 @@ function edit_link($row)
                trans_editor_link(ST_PURCHORDER, $row["order_no"]);
 }
 
+function receive_link($row) 
+{
+       global $page_nested;
+       
+       return $page_nested || !$row['OverDue'] ? '' :
+               pager_link( _("Receive"),
+                       "/purchasing/po_receive_items.php?PONumber=" . $row["order_no"], ICON_RECEIVE);
+}
+
 function prt_link($row)
 {
        return print_document_link($row['order_no'], _("Print"), true, ST_PURCHORDER, ICON_PRINT);
@@ -116,7 +125,8 @@ $cols = array(
                _("Currency") => array('align'=>'center'), 
                _("Order Total") => 'amount',
                array('insert'=>true, 'fun'=>'edit_link'),
-               array('insert'=>true, 'fun'=>'prt_link'),
+               array('insert'=>true, 'fun'=>'receive_link'),
+               array('insert'=>true, 'fun'=>'prt_link')
 );
 
 if (get_post('StockLocation') != ALL_TEXT) {
index 4b0d200a1d421c224033612ea7eac0408b2625e8..3c036b9a025fb99e5eb544e64e0caa93b53e424e 100644 (file)
@@ -181,9 +181,9 @@ $cols = array(
                        _("Amount") => array('align'=>'right', 'fun'=>'fmt_amount'), 
                        _("Balance") => array('align'=>'right', 'type'=>'amount'),
                        array('insert'=>true, 'fun'=>'gl_view'),
+                       array('insert'=>true, 'fun'=>'edit_link'),
                        array('insert'=>true, 'fun'=>'credit_link'),
-                       array('insert'=>true, 'fun'=>'prt_link'),
-                       array('insert'=>true, 'fun'=>'edit_link')
+                       array('insert'=>true, 'fun'=>'prt_link')
                        );
 
 if ($_POST['supplier_id'] != ALL_TEXT)
index 89026989718c7f136b204db5fe9cf1bc68bcc9fd..9cab778f183faccc850ebbeb39be035dbde9f8ba 100644 (file)
@@ -31,7 +31,113 @@ if (isset($_GET['supplier_id']))
        $_POST['supplier_id'] = $_GET['supplier_id'];
 }
 
-$supplier_id = get_post('supplier_id'); 
+$supplier_id = get_post('supplier_id', ''); 
+
+function can_process()
+{
+       /* actions to take once the user has clicked the submit button
+       ie the page has called itself with some user input */
+
+       //first off validate inputs sensible
+
+       if (strlen($_POST['supp_name']) == 0 || $_POST['supp_name'] == "") 
+       {
+               display_error(_("The supplier name must be entered."));
+               set_focus('supp_name');
+               return false;
+       }
+
+       if (strlen($_POST['supp_ref']) == 0 || $_POST['supp_ref'] == "") 
+       {
+               display_error(_("The supplier short name must be entered."));
+               set_focus('supp_ref');
+               return false;
+       }
+       return true;
+}
+
+function handle_submit(&$supplier_id)
+{
+       global $path_to_root, $Ajax, $SysPrefs;
+       
+       if (!can_process())
+               return;
+       begin_transaction();
+       if ($supplier_id) 
+       {
+               update_supplier($_POST['supplier_id'], $_POST['supp_name'], $_POST['supp_ref'], $_POST['address'],
+                       $_POST['supp_address'], $_POST['gst_no'],
+                       $_POST['website'], $_POST['supp_account_no'], $_POST['bank_account'], 
+                       input_num('credit_limit', 0), $_POST['dimension_id'], $_POST['dimension2_id'], $_POST['curr_code'],
+                       $_POST['payment_terms'], $_POST['payable_account'], $_POST['purchase_account'], $_POST['payment_discount_account'],
+                       $_POST['notes'], $_POST['tax_group_id'], check_value('tax_included'));
+               update_record_status($_POST['supplier_id'], $_POST['inactive'],
+                       'suppliers', 'supplier_id');
+
+               $Ajax->activate('supplier_id'); // in case of status change
+               display_notification(_("Supplier has been updated."));
+       } 
+       else 
+       {
+               add_supplier($_POST['supp_name'], $_POST['supp_ref'], $_POST['address'], $_POST['supp_address'],
+                       $_POST['gst_no'], $_POST['website'], $_POST['supp_account_no'], $_POST['bank_account'], 
+                       input_num('credit_limit',0), $_POST['dimension_id'], $_POST['dimension2_id'],
+                       $_POST['curr_code'], $_POST['payment_terms'], $_POST['payable_account'], $_POST['purchase_account'],
+                       $_POST['payment_discount_account'], $_POST['notes'], $_POST['tax_group_id'], check_value('tax_included'));
+
+               $supplier_id = $_POST['supplier_id'] = db_insert_id();
+
+               add_crm_person($_POST['supp_ref'], $_POST['contact'], '', $_POST['address'], 
+                       $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['email'], 
+                       $_POST['rep_lang'], '');
+
+               add_crm_contact('supplier', 'general', $supplier_id, db_insert_id());
+
+               display_notification(_("A new supplier has been added."));
+               $Ajax->activate('_page_body');
+       }
+       commit_transaction();
+}
+
+if (isset($_POST['submit'])) 
+{
+       handle_submit($supplier_id);
+}
+
+if (isset($_POST['delete']) && $_POST['delete'] != "") 
+{
+       //the link to delete a selected record was clicked instead of the submit button
+
+       $cancel_delete = 0;
+
+       // PREVENT DELETES IF DEPENDENT RECORDS IN 'supp_trans' , purch_orders
+
+       if (key_in_foreign_table($_POST['supplier_id'], 'supp_trans', 'supplier_id'))
+       {
+               $cancel_delete = 1;
+               display_error(_("Cannot delete this supplier because there are transactions that refer to this supplier."));
+
+       } 
+       else 
+       {
+               if (key_in_foreign_table($_POST['supplier_id'], 'purch_orders', 'supplier_id'))
+               {
+                       $cancel_delete = 1;
+                       display_error(_("Cannot delete the supplier record because purchase orders have been created against this supplier."));
+               }
+
+       }
+       if ($cancel_delete == 0) 
+       {
+               delete_supplier($_POST['supplier_id']);
+
+               unset($_SESSION['supplier_id']);
+               $supplier_id = '';
+               $Ajax->activate('_page_body');
+               display_notification("#" . $_POST['supplier_id'] . " " . _("Supplier has been deleted."));
+       } //end if Delete supplier
+}
+
 //--------------------------------------------------------------------------------------------
 function supplier_settings(&$supplier_id)
 {
@@ -70,26 +176,28 @@ function supplier_settings(&$supplier_id)
        } 
        else 
        {
-               $_POST['supp_name'] = $_POST['supp_ref'] = $_POST['address'] = $_POST['supp_address'] = 
-                       $_POST['tax_group_id'] = $_POST['website'] = $_POST['supp_account_no'] = $_POST['notes'] = '';
-               $_POST['dimension_id'] = 0;
-               $_POST['dimension2_id'] = 0;
-               $_POST['tax_included'] = 0;
-               $_POST['sales_type'] = -1;
-               $_POST['gst_no'] = $_POST['bank_account'] = '';
-               $_POST['payment_terms']  = '';
-               $_POST['credit_limit'] = price_format(0);
-
-               $company_record = get_company_prefs();
-               $_POST['curr_code']  = $company_record["curr_default"];
-               $_POST['payable_account'] = $company_record["creditors_act"];
-               $_POST['purchase_account'] = ''; // default/item's cogs account
-               $_POST['payment_discount_account'] = $company_record['pyt_discount_act'];
+               if (list_updated('supplier_id') || !isset($_POST['supp_name'])) {
+                       $_POST['supp_name'] = $_POST['supp_ref'] = $_POST['address'] = $_POST['supp_address'] = 
+                               $_POST['tax_group_id'] = $_POST['website'] = $_POST['supp_account_no'] = $_POST['notes'] = '';
+                       $_POST['dimension_id'] = 0;
+                       $_POST['dimension2_id'] = 0;
+                       $_POST['tax_included'] = 0;
+                       $_POST['sales_type'] = -1;
+                       $_POST['gst_no'] = $_POST['bank_account'] = '';
+                       $_POST['payment_terms']  = '';
+                       $_POST['credit_limit'] = price_format(0);
+
+                       $company_record = get_company_prefs();
+                       $_POST['curr_code']  = $company_record["curr_default"];
+                       $_POST['payable_account'] = $company_record["creditors_act"];
+                       $_POST['purchase_account'] = ''; // default/item's cogs account
+                       $_POST['payment_discount_account'] = $company_record['pyt_discount_act'];
+               }
        }
 
        table_section_title(_("Basic Data"));
 
-       text_row(_("Supplier Name:"), 'supp_name', null, 42, 40);
+       text_row(_("Supplier Name:"), 'supp_name', null, 42, 60);
        text_row(_("Supplier Short Name:"), 'supp_ref', null, 30, 30);
 
        text_row(_("GSTNo:"), 'gst_no', null, 42, 40);
@@ -183,106 +291,6 @@ function supplier_settings(&$supplier_id)
        div_end();
 }
 
-if (isset($_POST['submit'])) 
-{
-
-       //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 */
-
-       //first off validate inputs sensible
-
-       if (strlen($_POST['supp_name']) == 0 || $_POST['supp_name'] == "") 
-       {
-               $input_error = 1;
-               display_error(_("The supplier name must be entered."));
-               set_focus('supp_name');
-       }
-
-       if (strlen($_POST['supp_ref']) == 0 || $_POST['supp_ref'] == "") 
-       {
-               $input_error = 1;
-               display_error(_("The supplier short name must be entered."));
-               set_focus('supp_ref');
-       }
-
-       if ($input_error !=1 )
-       {
-
-               begin_transaction();
-               if ($supplier_id) 
-               {
-                       update_supplier($_POST['supplier_id'], $_POST['supp_name'], $_POST['supp_ref'], $_POST['address'],
-                               $_POST['supp_address'], $_POST['gst_no'],
-                               $_POST['website'], $_POST['supp_account_no'], $_POST['bank_account'], 
-                               input_num('credit_limit', 0), $_POST['dimension_id'], $_POST['dimension2_id'], $_POST['curr_code'],
-                               $_POST['payment_terms'], $_POST['payable_account'], $_POST['purchase_account'], $_POST['payment_discount_account'],
-                               $_POST['notes'], $_POST['tax_group_id'], check_value('tax_included'));
-                       update_record_status($_POST['supplier_id'], $_POST['inactive'],
-                               'suppliers', 'supplier_id');
-
-                       $Ajax->activate('supplier_id'); // in case of status change
-                       display_notification(_("Supplier has been updated."));
-               } 
-               else 
-               {
-                       add_supplier($_POST['supp_name'], $_POST['supp_ref'], $_POST['address'], $_POST['supp_address'],
-                               $_POST['gst_no'], $_POST['website'], $_POST['supp_account_no'], $_POST['bank_account'], 
-                               input_num('credit_limit',0), $_POST['dimension_id'], $_POST['dimension2_id'],
-                               $_POST['curr_code'], $_POST['payment_terms'], $_POST['payable_account'], $_POST['purchase_account'],
-                               $_POST['payment_discount_account'], $_POST['notes'], $_POST['tax_group_id'], check_value('tax_included'));
-
-                       $supplier_id = $_POST['supplier_id'] = db_insert_id();
-
-                       add_crm_person($_POST['supp_ref'], $_POST['contact'], '', $_POST['address'], 
-                               $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['email'], 
-                               $_POST['rep_lang'], '');
-
-                       add_crm_contact('supplier', 'general', $supplier_id, db_insert_id());
-
-                       display_notification(_("A new supplier has been added."));
-                       $Ajax->activate('_page_body');
-               }
-               commit_transaction();
-       }
-
-} 
-elseif (isset($_POST['delete']) && $_POST['delete'] != "") 
-{
-       //the link to delete a selected record was clicked instead of the submit button
-
-       $cancel_delete = 0;
-
-       // PREVENT DELETES IF DEPENDENT RECORDS IN 'supp_trans' , purch_orders
-
-       if (key_in_foreign_table($_POST['supplier_id'], 'supp_trans', 'supplier_id'))
-       {
-               $cancel_delete = 1;
-               display_error(_("Cannot delete this supplier because there are transactions that refer to this supplier."));
-
-       } 
-       else 
-       {
-               if (key_in_foreign_table($_POST['supplier_id'], 'purch_orders', 'supplier_id'))
-               {
-                       $cancel_delete = 1;
-                       display_error(_("Cannot delete the supplier record because purchase orders have been created against this supplier."));
-               }
-
-       }
-       if ($cancel_delete == 0) 
-       {
-               delete_supplier($_POST['supplier_id']);
-
-               unset($_SESSION['supplier_id']);
-               $supplier_id = '';
-               $Ajax->activate('_page_body');
-               display_notification("#" . $_POST['supplier_id'] . " " . _("Supplier has been deleted."));
-       } //end if Delete supplier
-}
-
 start_form();
 
 if (db_has_suppliers()) 
index 9335c1f1e81348ceb72e96cda1858cd3698264ce..461c80443496d3c64ca223dd2e8aa77d1c2266b0 100644 (file)
@@ -29,7 +29,7 @@ if (user_use_date_picker())
 //----------------------------------------------------------------------------------------
 
 if (isset($_GET['ModifyCredit']))
-       check_is_editable(ST_SUPPINVOICE, $_GET['ModifyCredit']);
+       check_is_editable(ST_SUPPCREDIT, $_GET['ModifyCredit']);
 
 //---------------------------------------------------------------------------------------------------
 
@@ -282,8 +282,7 @@ function commit_item_data($n)
                $_POST['po_detail_item'.$n], $_POST['item_code'.$n],
                $_POST['item_description'.$n], $_POST['qty_recd'.$n],
                $_POST['prev_quantity_inv'.$n], input_num('This_QuantityCredited'.$n),
-               $_POST['order_price'.$n], input_num('ChgPrice'.$n),
-               $_POST['std_cost_unit'.$n], "");
+               $_POST['order_price'.$n], input_num('ChgPrice'.$n));
                reset_tax_input();
        }
 }
index a21d0c9123d846c8f98ab1c8903472e7d6e3bde5..0dc1a77ad90444f74649e2ceefbec5e118c8dd13 100644 (file)
@@ -295,20 +295,10 @@ function commit_item_data($n)
 {
        if (check_item_data($n))
        {
-       if (input_num('this_quantity_inv'.$n) >= ($_POST['qty_recd'.$n] - $_POST['prev_quantity_inv'.$n]))
-       {
-               $complete = true;
-       }
-       else
-       {
-               $complete = false;
-       }
-
                $_SESSION['supp_trans']->add_grn_to_trans($n, $_POST['po_detail_item'.$n],
                        $_POST['item_code'.$n], $_POST['item_description'.$n], $_POST['qty_recd'.$n],
                        $_POST['prev_quantity_inv'.$n], input_num('this_quantity_inv'.$n),
-                       $_POST['order_price'.$n], input_num('ChgPrice'.$n), $complete,
-                       $_POST['std_cost_unit'.$n], "");
+                       $_POST['order_price'.$n], input_num('ChgPrice'.$n));
                reset_tax_input();
        }
 }
index 236c462283ff316f328f76e81412a9378cc356ca..b2d95bb8e26390226249069d414976456536ef51 100644 (file)
@@ -37,20 +37,30 @@ display_grn_summary($purchase_order);
 display_heading2(_("Line Details"));
 
 start_table(TABLESTYLE, "width='90%'");
-$th = array(_("Item Code"), _("Item Description"), _("Delivery Date"), _("Quantity"),
+$th = array(_("Item Code"), _("Item Description"), _("Required by"), _("Quantity"),
        _("Unit"), _("Price"), _("Line Total"), _("Quantity Invoiced"));
 
 table_header($th);
 
 $total = 0;
 $k = 0;  //row colour counter
+$overdue_items = false;
 
 foreach ($purchase_order->line_items as $stock_item)
 {
 
        $line_total = $stock_item->qty_received * $stock_item->price;
 
-       alt_table_row_color($k);
+       // if overdue and outstanding quantities, then highlight as so
+       if (date1_greater_date2($purchase_order->orig_order_date, $stock_item->req_del_date))
+       {
+       start_row("class='overduebg'");
+       $overdue_items = true;
+       }
+       else
+       {
+               alt_table_row_color($k);
+       }
 
        label_cell($stock_item->stock_id);
        label_cell($stock_item->item_description);
@@ -83,6 +93,9 @@ end_row();
 
 end_table(1);
 
+if ($overdue_items)
+       display_note(_("Marked items were delivered overdue."), 0, 0, "class='overduefg'");
+
 is_voided_display(ST_SUPPRECEIVE, $_GET['trans_no'], _("This delivery has been voided."));
 
 end_page(true, false, false, ST_SUPPRECEIVE, $_GET['trans_no']);
index ab76ab46ed20fb3311ef59e971682608a97b64ae..4f34ab7d2c99c1432f387c116119f2944b47b63f 100644 (file)
@@ -306,17 +306,26 @@ class Cpdf extends FPDI {
                                $align = 'J';
                }
                else
-                       $align = 'R';
+               {
+                       if ($align == 'right')
+                               $align = 'R';// This may need to be 'L'
+                       elseif ($align == 'left')
+                               $align = 'R';
+                       elseif ($align == 'center')
+                               $align = 'C';
+                       elseif ($align == 'justify')
+                               $align = 'J';
+               }
 
                $txt = parent::unhtmlentities($txt);
                // If horizontal scaling was requested, check to see if we're trying to scale
                // too much.  If so, cut back string first and then scale it.
                $maxScaleFactor = 1.4;
                if ($stretch == 1 || $stretch == 2)
-               $txt = $this->calcTextWrap($txt, $w * $maxScaleFactor, $spacebreak);
+                       $txt = $this->calcTextWrap($txt, $w * $maxScaleFactor, $spacebreak);
                // Wrap text if stretching isn't turned on
                else
-               $txt = $this->calcTextWrap($txt, $w, $spacebreak);
+                       $txt = $this->calcTextWrap($txt, $w, $spacebreak);
                $ret = $txt[1];
                $txt = $txt[0];
                $this->SetXY($xb, $this->h - $yb - $h);
index 6062ddca554ef024ca0ead27085e815041a3e31a..0267687d115a6d1efd81c24ea488655f02969ac1 100644 (file)
@@ -117,6 +117,16 @@ function print_document_link($doc_no, $link_text, $link=true, $type_no,
                                'PARAM_3' => '', 
                                'PARAM_4' => $def_orientation);
                        break;
+               case ST_DIMENSION :
+                       $rep = 501;
+                       // from, to, email, comments, orientation
+                       $ar = array(
+                               'PARAM_0' => $doc_no, 
+                               'PARAM_1' => $doc_no, 
+                               'PARAM_2' => 1, 
+                               'PARAM_3' => '', 
+                               'PARAM_4' => $def_orientation);
+                       break;
                default:
                        return null;
        }
index f9ea4499eaa518989504200dc95017dd4ee467fe..1274a8df9cb94b4018c63e7f1940b2cafbb9ef3b 100644 (file)
@@ -49,6 +49,7 @@ function GetSalesmanTrans($from, $to)
                        ".TB_PREF."salesman salesman
                WHERE sorder.order_no=trans.order_
                    AND sorder.branch_code=branch.branch_code
+                   AND sorder.trans_type = ".ST_SALESORDER."
                    AND branch.salesman=salesman.salesman_code
                    AND trans.debtor_no=cust.debtor_no
                    AND (trans.type=".ST_SALESINVOICE." OR trans.type=".ST_CUSTCREDIT.")
index ec7c3afbea4a45d4de7be743f8a8a2f9dcc7329e..a1f6a61c5e6ac2af3694a4563bd7f25404c7f8b3 100644 (file)
@@ -124,7 +124,7 @@ function get_allocatable_from_cust_sql($customer_id=null, $settled)
                 OR (type=".ST_JOURNAL. " AND (trans.ov_amount < 0)))";
 
        if (!$settled)
-               $sql .= " AND (round(abs(ov_amount+ov_gst+ov_freight+ov_freight_tax-ov_discount-alloc),6) > 0)";
+               $sql .= " AND (round(abs(ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount-alloc),6) > 0)";
 
        if ($customer_id != null)
                $sql .= " AND trans.debtor_no = ".db_escape($customer_id);
index ae763fca3eea45165a552817c815f18f283fefb4..311bc3f2c43283ec838c29dc2c00e0b7daa29148 100644 (file)
@@ -490,7 +490,7 @@ function sales_order_item_controls(&$order, &$rowcounter, $line_no=-1)
                hidden('stock_id', $_POST['stock_id']);
                label_cell($_POST['stock_id']);
                if ($order->line_items[$id]->descr_editable)
-                       text_cells(null,'item_description', null, 45, 150);
+                       text_cells(null,'item_description', null, 45, 50);
                else {
                        hidden('item_description', $_POST['item_description']);
                        label_cell($_POST['item_description']);
index eb98d3dad278b040f247b8df3a2f75d7d4dd7bb7..2183dd1b2ae4b15c91d5d2ddd6ab38ddb7117b85 100644 (file)
@@ -70,9 +70,15 @@ function credit_link($row)
 
        if ($page_nested)
                return '';
-       return $row['type'] == ST_SALESINVOICE && $row["Outstanding"] > 0 ?
-               pager_link(_("Credit This") ,
-                       "/sales/customer_credit_invoice.php?InvoiceNumber=". $row['trans_no'], ICON_CREDIT):'';
+       if ($row["Outstanding"] > 0)
+       {
+               if ($row['type'] == ST_CUSTDELIVERY)
+                       return pager_link(_('Invoice'), "/sales/customer_invoice.php?DeliveryNumber=" 
+                               .$row['trans_no'], ICON_DOC);
+               else if ($row['type'] == ST_SALESINVOICE)
+                       return pager_link(_("Credit This") ,
+                       "/sales/customer_credit_invoice.php?InvoiceNumber=". $row['trans_no'], ICON_CREDIT);
+       }       
 }
 
 function edit_link($row)
@@ -203,8 +209,8 @@ $cols = array(
        _("Amount") => array('align'=>'right', 'fun'=>'fmt_amount'), 
        _("Balance") => array('align'=>'right', 'type'=>'amount'),
                array('insert'=>true, 'fun'=>'gl_view'),
-               array('insert'=>true, 'fun'=>'credit_link'),
                array('insert'=>true, 'fun'=>'edit_link'),
+               array('insert'=>true, 'fun'=>'credit_link'),
                array('insert'=>true, 'fun'=>'prt_link')
        );
 
index 2241e1f9dc05a7fe9c157f64d8e738280ec16a9c..bc08889900f31fed6abf17d7a58d32c179c27d73 100644 (file)
@@ -114,14 +114,19 @@ function edit_link($row)
 
 function dispatch_link($row)
 {
-       global $trans_type;
+       global $trans_type, $page_nested;
 
        if ($row['ord_payments'] + $row['inv_payments'] < $row['prep_amount'])
                return '';
 
        if ($trans_type == ST_SALESORDER)
-               return pager_link( _("Dispatch"),
-                       "/sales/customer_delivery.php?OrderNumber=" .$row['order_no'], ICON_DOC);
+       {
+               if ($row['TotDelivered'] < $row['TotQuantity'] && !$page_nested)
+                       return pager_link( _("Dispatch"),
+                               "/sales/customer_delivery.php?OrderNumber=" .$row['order_no'], ICON_DOC);
+               else
+                       return '';
+       }               
        else
                return pager_link( _("Sales Order"),
                        "/sales/sales_order_entry.php?OrderNumber=" .$row['order_no'], ICON_DOC);
@@ -277,8 +282,9 @@ else
        );
 if ($_POST['order_view_mode'] == 'OutstandingOnly') {
        array_append($cols, array(
+               array('insert'=>true, 'fun'=>'edit_link'),
                array('insert'=>true, 'fun'=>'dispatch_link'),
-               array('insert'=>true, 'fun'=>'edit_link')));
+               array('insert'=>true, 'fun'=>'prt_link')));
 
 } elseif ($_POST['order_view_mode'] == 'InvoiceTemplates') {
        array_substitute($cols, 4, 1, _("Description"));
@@ -303,6 +309,7 @@ if ($_POST['order_view_mode'] == 'OutstandingOnly') {
         array_append($cols,array(
                        _("Tmpl") => array('insert'=>true, 'fun'=>'tmpl_checkbox'),
                                        array('insert'=>true, 'fun'=>'edit_link'),
+                                       array('insert'=>true, 'fun'=>'dispatch_link'),
                                        array('insert'=>true, 'fun'=>'prt_link')));
 };