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/prefs/sysprefs.inc");
13 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
25 var $editing_item, $deleting_item;
36 function items_cart($type)
38 $this->trans_type = $type;
42 // --------------- line item functions
44 function add_to_cart($line_no, $stock_id, $qty, $standard_cost, $description=null)
47 if (isset($stock_id) && $stock_id != "" && isset($qty))
49 $this->line_items[$line_no] = new line_item($stock_id, $qty,
50 $standard_cost, $description);
55 // shouldn't come here under normal circumstances
56 display_db_error("unexpected - adding an invalid item or null quantity", "", true);
62 function find_cart_item($stock_id)
64 foreach($this->line_items as $line_no=>$line) {
65 if ($line->stock_id == $stock_id)
66 return $this->line_items[$line_no];
71 function update_cart_item($line_no, $qty, $standard_cost)
73 $this->line_items[$line_no]->quantity = $qty;
74 $this->line_items[$line_no]->standard_cost = $standard_cost;
77 function remove_from_cart($line_no)
79 array_splice($this->line_items, $line_no, 1);
82 function count_items()
84 return count($this->line_items);
87 function check_qoh($location, $date_, $reverse=false)
89 foreach ($this->line_items as $line_no => $line_item)
91 $item_ret = $line_item->check_qoh($location, $date_, $reverse);
92 if ($item_ret != null)
98 // ----------- GL item functions
100 function add_gl_item($code_id, $dimension_id, $dimension2_id, $amount, $reference, $description=null)
102 if (isset($code_id) && $code_id != "" && isset($amount) && isset($dimension_id) &&
103 isset($dimension2_id))
105 $this->gl_items[$this->gl_item_count] = new gl_item($this->gl_item_count,
106 $code_id, $dimension_id, $dimension2_id, $amount, $reference, $description);
107 $this->gl_item_count++;
112 // shouldn't come here under normal circumstances
113 display_db_error("unexpected - invalid parameters in add_gl_item($code_id, $dimension_id, $dimension2_id, $amount,...)", "", true);
119 function update_gl_item($index, $dimension_id, $dimension2_id, $amount, $reference, $description=null)
121 $this->gl_items[$index]->index = $index;
122 $this->gl_items[$index]->dimension_id = $dimension_id;
123 $this->gl_items[$index]->dimension2_id = $dimension2_id;
124 $this->gl_items[$index]->amount = $amount;
125 $this->gl_items[$index]->reference = $reference;
126 if ($description != null)
127 $this->gl_items[$index]->description = $description;
131 function remove_gl_item($index)
135 array_splice($this->gl_items, $line_no, 1);
139 function count_gl_items()
141 return count($this->gl_items);
144 function gl_items_total()
147 foreach ($this->gl_items as $gl_item)
148 $total += $gl_item->amount;
152 function gl_items_total_debit()
155 foreach ($this->gl_items as $gl_item)
157 if ($gl_item->amount > 0)
158 $total += $gl_item->amount;
163 function gl_items_total_credit()
166 foreach ($this->gl_items as $gl_item)
168 if ($gl_item->amount < 0)
169 $total += $gl_item->amount;
174 // ------------ common functions
176 function clear_items()
178 unset($this->line_items);
179 $this->line_items = array();
181 unset($this->gl_items);
182 $this->gl_items = array();
183 $this->gl_item_count = 1;
188 //--------------------------------------------------------------------------------------------
193 var $item_description;
201 function line_item ($stock_id, $qty, $standard_cost=null, $description=null)
203 $item_row = get_item($stock_id);
205 if ($item_row == null)
206 display_db_error("invalid item added to order : $stock_id", "");
208 $this->mb_flag = $item_row["mb_flag"];
209 $this->units = $item_row["units"];
211 if ($description == null)
212 $this->item_description = $item_row["description"];
214 $this->item_description = $description;
216 if ($standard_cost == null)
217 $this->standard_cost = $item_row["actual_cost"];
219 $this->standard_cost = $standard_cost;
221 $this->stock_id = $stock_id;
222 $this->quantity = $qty;
223 //$this->price = $price;
227 function check_qoh($location, $date_, $reverse)
229 if (!sys_prefs::allow_negative_stock())
231 if (has_stock_holding($this->mb_flag))
233 $quantity = $this->quantity;
235 $quantity = -$this->quantity;
240 $qoh = get_qoh_on_date($this->stock_id, $location, $date_);
241 if ($quantity + $qoh < 0)
252 //---------------------------------------------------------------------------------------
265 function gl_item($index, $code_id, $dimension_id, $dimension2_id, $amount, $reference,
268 //echo "adding $index, $code_id, $dimension_id, $amount, $reference<br>";
270 if ($description == null)
271 $this->description = get_gl_account_name($code_id);
273 $this->description = $description;
275 $this->index = $index;
276 $this->code_id = $code_id;
277 $this->dimension_id = $dimension_id;
278 $this->dimension2_id = $dimension2_id;
279 $this->amount = $amount;
280 $this->reference = $reference;
284 //---------------------------------------------------------------------------------------