f3c0f5dcf167b2598ab3c9d6e46426f89d950d21
[fa-stable.git] / inventory / includes / stock_transfers_ui.inc
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 include_once($path_to_root . "/includes/ui.inc");
13 include_once($path_to_root . "/includes/ui/items_cart.inc");
14
15 //--------------------------------------------------------------------------------
16
17 function add_to_order(&$order, $new_item, $new_item_qty, $standard_cost)
18 {
19     if ($order->find_cart_item($new_item))
20          display_error(_("For Part :") . $new_item . " " . "This item is already on this document. You can change the quantity on the existing line if necessary.");
21         else
22          $order->add_to_cart (count($order->line_items), $new_item, $new_item_qty, $standard_cost);
23 }
24
25 //--------------------------------------------------------------------------------
26
27 function display_order_header(&$order)
28 {
29         global $Refs;
30
31         start_outer_table(TABLESTYLE, "width='70%'");
32
33         table_section(1);
34         
35         locations_list_row(_("From Location:"), 'FromStockLocation', null);
36         locations_list_row(_("To Location:"), 'ToStockLocation', null);
37
38         table_section(2, "50%");
39
40     date_row(_("Date:"), 'AdjDate', '', true);
41
42         ref_row(_("Reference:"), 'ref', '', $Refs->get_next(ST_LOCTRANSFER, null, array('date'=>get_post('Adjdate'), 'location'=> get_post('FromStockLocation'))),
43                  false, ST_LOCTRANSFER);
44
45         end_outer_table(1); // outer table
46 }
47
48 //---------------------------------------------------------------------------------
49
50 function display_transfer_items($title, &$order)
51 {
52         global $path_to_root;
53
54         display_heading($title);
55     div_start('items_table');
56         start_table(TABLESTYLE, "width='80%'");
57         $th = array(_("Item Code"), _("Item Description"), _("Quantity"), _("Unit"), '');
58         if ( count($order->line_items)) $th[] = '';
59         table_header($th);
60         $k = 0;  //row colour counter
61
62         $low_stock = $order->check_qoh($_POST['FromStockLocation'], $_POST['AdjDate'], true);
63         $id = find_submit('Edit');
64         foreach ($order->line_items as $line_no=>$stock_item)
65         {
66
67                 if ($id != $line_no)
68                 {
69                         if (in_array($stock_item->stock_id, $low_stock))
70                                 start_row("class='stockmankobg'");      // notice low stock status
71                         else 
72                                 alt_table_row_color($k);
73
74                         view_stock_status_cell($stock_item->stock_id);
75                 label_cell($stock_item->item_description);
76                 qty_cell($stock_item->quantity, false, get_qty_dec($stock_item->stock_id));
77                 label_cell($stock_item->units);
78
79                         edit_button_cell("Edit$line_no", _("Edit"),
80                                 _('Edit document line'));
81                         delete_button_cell("Delete$line_no", _("Delete"),
82                                 _('Remove line from document'));
83                 end_row();
84                 }
85                 else
86                 {
87                         transfer_edit_item_controls($order, $line_no);
88                 }
89         }
90
91         if ($id == -1)
92                 transfer_edit_item_controls($order);
93
94     end_table();
95         if ($low_stock)
96                 display_note(_("Marked items have insufficient quantities in stock as on day of transfer."), 0, 1, "class='stockmankofg'");
97         div_end();
98 }
99
100 //---------------------------------------------------------------------------------
101
102 function transfer_edit_item_controls(&$order, $line_no=-1)
103 {
104         global $Ajax;
105         start_row();
106
107         $id = find_submit('Edit');
108         if ($line_no != -1 && $line_no == $id)
109         {
110                 $_POST['stock_id'] = $order->line_items[$id]->stock_id;
111                 $_POST['qty'] = qty_format($order->line_items[$id]->quantity, $order->line_items[$id]->stock_id, $dec);
112                 $_POST['units'] = $order->line_items[$id]->units;
113
114                 hidden('stock_id', $_POST['stock_id']);
115                 label_cell($_POST['stock_id']);
116                 label_cell($order->line_items[$id]->item_description);
117             $Ajax->activate('items_table');
118         }
119         else
120         {
121         stock_costable_items_list_cells(null, 'stock_id', null, false, true);
122                 if (list_updated('stock_id')) {
123                             $Ajax->activate('units');
124                             $Ajax->activate('qty');
125                 }
126
127         $item_info = get_item_edit_info($_POST['stock_id']);
128
129                 $dec = $item_info['decimals'];
130                 $_POST['qty'] = number_format2(0, $dec);
131                 $_POST['units'] = $item_info["units"];
132         }
133
134         small_qty_cells(null, 'qty', $_POST['qty'], null, null, $dec);
135         label_cell($_POST['units'], '', 'units');
136
137         if ($id != -1)
138         {
139                 button_cell('UpdateItem', _("Update"),
140                                 _('Confirm changes'), ICON_UPDATE);
141                 button_cell('CancelItemChanges', _("Cancel"),
142                                 _('Cancel changes'), ICON_CANCEL);
143                 hidden('LineNo', $line_no);
144                 set_focus('qty');
145         }
146         else
147         {
148                 submit_cells('AddItem', _("Add Item"), "colspan=2",
149                     _('Add new item to document'), true);
150         }
151
152         end_row();
153 }
154
155
156 //---------------------------------------------------------------------------------
157
158 function transfer_options_controls()
159 {
160           echo "<br>";
161           start_table();
162
163           textarea_row(_("Memo"), 'memo_', null, 50, 3);
164
165           end_table(1);
166 }
167
168
169 //---------------------------------------------------------------------------------
170