Final rewriting of sales module
[fa-stable.git] / sales / includes / ui / sales_credit_ui.inc
index 7b7002291c11af3c9c1d3274ff6dc5d08ada8904..751d7bd30cb8ba7debccd5a31f573705375a86fb 100644 (file)
@@ -44,8 +44,12 @@ function display_credit_header(&$order)
 
        if (!isset($_POST['ref']))
                $_POST['ref'] = references::get_next(11);
+       if ($_SESSION['Items']->trans_no==0)
+           ref_row(_("Reference:"), 'ref');
+       else
+           label_row(_("Reference"), $_POST['ref'], "class='tableheader2'");
+       
 
-       ref_row(_("Reference:"), 'ref');
 
        echo "</table>";
 
@@ -75,13 +79,14 @@ function display_credit_header(&$order)
        echo "<table height='5'>";
 
        if (!isset($_POST['OrderDate']) || $_POST['OrderDate'] == "")
-               $_POST['OrderDate'] = $order->orig_order_date;
+               $_POST['OrderDate'] = $order->document_date;
 
        date_row(_("Date:"), 'OrderDate');
 
-       if (!isset($_POST['tax_group_id']) || $_POST['tax_group_id'] == "")
-               $_POST['tax_group_id'] = $order->tax_group_id;
-    tax_groups_list_row(_("Tax Group:"), 'tax_group_id', null, true);
+//     if (!isset($_POST['tax_group_id']) || $_POST['tax_group_id'] == "")
+//             $_POST['tax_group_id'] = $order->tax_group_id;
+//    tax_groups_list_row(_("Tax Group:"), 'tax_group_id', null, true);
+    shippers_list_row(_("Shipping Company:"), 'ShipperID', $order->ship_via);
 
        echo "</table>";
 
@@ -101,32 +106,39 @@ function display_credit_items($title, &$order)
        display_heading($title);
        start_table("$table_style width=90%");
        $th = array(_("Item Code"), _("Item Description"), _("Quantity"), _("Unit"),
-               _("Price"), _("Discount %"), _("Total"));
+               _("Price"), _("Discount %"), _("Total"),'');
+
+       if (count($order->line_items)) $th[]= '';
+
        table_header($th);
 
        $subtotal = 0;
        $k = 0;  //row colour counter
 
-       foreach ($order->line_items as $line)
+       foreach ($order->line_items as $line_no=>$line)
        {
+               $line_total =   $line->qty_dispatched * $line->price * (1 - $line->discount_percent);
+               if (!isset($_GET['Edit']))
+                       $id = -1;
+               else
+                       $id = $_GET['Edit'];
 
-               $line_total =   $line->quantity * $line->price * (1 - $line->discount_percent);
+                if ( $id != $line_no)
 
-               if (!isset($_GET['Edit']) || $_GET['Edit'] != $line->line_no)
                {
                alt_table_row_color($k);
 
                label_cell("<a target='_blank' href='$path_to_root/inventory/inquiry/stock_status.php?" . SID . "stock_id=" . $line->stock_id . "'>$line->stock_id</a>");
                label_cell($line->item_description);
-               qty_cell($line->quantity);
+               qty_cell($line->qty_dispatched);
                label_cell($line->units);
                amount_cell($line->price);
 
-                       amount_cell($line->discount_percent * 100);
+               amount_cell($line->discount_percent * 100);
                amount_cell($line_total);
 
-               edit_link_cell(SID . "Edit=$line->line_no");
-               delete_link_cell(SID . "Delete=$line->line_no");
+               edit_link_cell(SID . "Edit=$line_no");
+               delete_link_cell(SID . "Delete=$line_no");
 
                        //labelt_cell(get_tax_free_price_for_item($line->stock_id, $line_total, $_POST['tax_group_id']));
 
@@ -134,7 +146,7 @@ function display_credit_items($title, &$order)
                }
                else
                {
-                       credit_edit_item_controls($order, $line->stock_id);
+                       credit_edit_item_controls($order, $line_no);
                }
 
                $subtotal += $line_total;
@@ -151,9 +163,9 @@ function display_credit_items($title, &$order)
 
        text_row(_("Shipping"), 'ChargeFreightCost', $_POST['ChargeFreightCost'], 8, 8, "colspan=6 align=right");
 
-    $taxes = $order->get_taxes($_POST['tax_group_id'], $_POST['ChargeFreightCost']);
+    $taxes = $order->get_taxes($_POST['ChargeFreightCost']);
 
-       $tax_total = display_edit_tax_items($taxes, 6);
+       $tax_total = display_edit_tax_items($taxes, 6, $_SESSION['Items']->tax_included);
 
     $display_total = number_format2(($subtotal + $_POST['ChargeFreightCost'] + $tax_total), user_price_dec());
     label_row(_("Credit Note Total"), $display_total, "colspan=6 align=right","align=right");
@@ -163,37 +175,41 @@ function display_credit_items($title, &$order)
 
 //---------------------------------------------------------------------------------
 
-function credit_edit_item_controls(&$order, $stock_id=null)
+function credit_edit_item_controls(&$order, $line_no=-1)
 {
        start_row();
-
-       if (isset($_GET['Edit']) and $stock_id!=null)
+       if (isset($_GET['Edit']) && $line_no != -1)
        {
-               $line_no = $_GET['Edit'];
-               hidden('line_no', $line_no);
 
                if (!isset($_POST['stock_id']))
-                       $_POST['stock_id'] = $order->line_items[$line_no]->stock_id;
-               if (!isset($_POST['qty']) OR ($_POST['qty']==""))
-                       $_POST['qty'] = $order->line_items[$line_no]->quantity;
-               if (!isset($_POST['price']) OR ($_POST['price']==""))
-                       $_POST['price'] = $order->line_items[$line_no]->price;
-               if (!isset($_POST['Disc']) OR ($_POST['Disc']==""))
-                       $_POST['Disc'] = ($order->line_items[$line_no]->discount_percent)*100;
+                       $_POST['stock_id'] = $order->line_items[$_GET['Edit']]->stock_id;
+               if (!isset($_POST['qty']) || ($_POST['qty']==""))
+                       $_POST['qty'] = $order->line_items[$_GET['Edit']]->qty_dispatched;
+               if (!isset($_POST['price']) || ($_POST['price']==""))
+                       $_POST['price'] = $order->line_items[$_GET['Edit']]->price;
+               if (!isset($_POST['Disc']) || ($_POST['Disc']==""))
+                       $_POST['Disc'] = ($order->line_items[$_GET['Edit']]->discount_percent)*100;
 
-               $_POST['units'] = $order->line_items[$line_no]->units;
+               $_POST['units'] = $order->line_items[$_GET['Edit']]->units;
 
                hidden('stock_id', $_POST['stock_id']);
                label_cell($_POST['stock_id']);
-               label_cell($order->line_items[$line_no]->item_description);
+               label_cell($order->line_items[$_GET['Edit']]->item_description);
        }
        else
        {
-               hidden('line_no', ($_SESSION['credit_items']->lines_on_order + 1));
-       echo "<td colspan=2>";
-       stock_items_list('stock_id', null, false, true);
-       echo "</td>";
-
+               global $no_item_list; 
+               if ($no_item_list)
+               {
+                       echo "<td colspan=2>\n";
+                       stock_items_list('stock_id', null, false, true);
+                       echo "</td>\n";
+               }
+               else
+               {
+                 text_cells(null, "StockID2", "", 12, 10, "", "", "onkeyup='recalcAccounts();' onKeyDown='if (event.keyCode==13) event.keyCode=9;' onblur='return setAccount(0, true);'");
+                       stock_items_list_cells(null, 'stock_id', null, false, false, "onchange='return setAccount(1, true)'");
+               }
        $item_info = get_item_edit_info($_POST['stock_id']);
 
                $_POST['units'] = $item_info["units"];
@@ -206,15 +222,20 @@ function credit_edit_item_controls(&$order, $stock_id=null)
 
 
        text_cells(null, 'qty', $_POST['qty'], 13, 15);
+//     if ($order->trans_no!=0) {
+//             amount_cell($line_no==-1 ? 0 :$order->line_items[$line_no]->qty_done);
+//     }
        label_cell($_POST['units']);
        text_cells(null, 'price',  null, 13, 15);
        text_cells(null, 'Disc', $_POST['Disc'], 7, 5);
+
        amount_cell($_POST['qty'] * $_POST['price'] * (1 - $_POST['Disc']/100));
 
        if (isset($_GET['Edit']))
        {
        submit_cells('UpdateItem', _("Update"));
        submit_cells('CancelItemChanges', _("Cancel"));
+               hidden('LineNo', $line_no);
        }
        else
        {
@@ -240,7 +261,7 @@ function credit_options_controls()
 
                /*if the credit note is a return of goods then need to know which location to receive them into */
                if (!isset($_POST['Location']))
-                       $_POST['Location'] = $_SESSION['credit_items']->Location;
+                       $_POST['Location'] = $_SESSION['Items']->Location;
                locations_list_row(_("Items Returned to Location"), 'Location', $_POST['Location']);
 
        }