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");
23 var $editing_item, $deleting_item;
35 function items_cart($type)
37 $this->trans_type = $type;
41 // --------------- line item functions
43 function add_to_cart($line_no, $stock_id, $qty, $standard_cost, $description=null)
46 if (isset($stock_id) && $stock_id != "" && isset($qty))
48 $this->line_items[$line_no] = new line_item($stock_id, $qty,
49 $standard_cost, $description);
54 // shouldn't come here under normal circumstances
55 display_db_error("unexpected - adding an invalid item or null quantity", "", true);
61 function find_cart_item($stock_id)
63 foreach($this->line_items as $line_no=>$line) {
64 if ($line->stock_id == $stock_id)
65 return $this->line_items[$line_no];
70 function update_cart_item($line_no, $qty, $standard_cost)
72 $this->line_items[$line_no]->quantity = $qty;
73 $this->line_items[$line_no]->standard_cost = $standard_cost;
76 function remove_from_cart($line_no)
78 array_splice($this->line_items, $line_no, 1);
81 function count_items()
83 return count($this->line_items);
86 function check_qoh($location, $date_, $reverse=false)
88 foreach ($this->line_items as $line_no => $line_item)
90 $item_ret = $line_item->check_qoh($location, $date_, $reverse);
91 if ($item_ret != null)
97 // ----------- GL item functions
99 function add_gl_item($code_id, $dimension_id, $dimension2_id, $amount, $reference, $description=null)
101 if (isset($code_id) && $code_id != "" && isset($amount) && isset($dimension_id) &&
102 isset($dimension2_id))
104 $this->gl_items[] = new gl_item($code_id, $dimension_id, $dimension2_id, $amount, $reference, $description);
109 // shouldn't come here under normal circumstances
110 display_db_error("unexpected - invalid parameters in add_gl_item($code_id, $dimension_id, $dimension2_id, $amount,...)", "", true);
116 function update_gl_item($index, $dimension_id, $dimension2_id, $amount, $reference, $description=null)
118 $this->gl_items[$index]->dimension_id = $dimension_id;
119 $this->gl_items[$index]->dimension2_id = $dimension2_id;
120 $this->gl_items[$index]->amount = $amount;
121 $this->gl_items[$index]->reference = $reference;
122 if ($description != null)
123 $this->gl_items[$index]->description = $description;
127 function remove_gl_item($index)
129 array_splice($this->gl_items, $index, 1);
132 function count_gl_items()
134 return count($this->gl_items);
137 function gl_items_total()
140 foreach ($this->gl_items as $gl_item)
141 $total += $gl_item->amount;
145 function gl_items_total_debit()
148 foreach ($this->gl_items as $gl_item)
150 if ($gl_item->amount > 0)
151 $total += $gl_item->amount;
156 function gl_items_total_credit()
159 foreach ($this->gl_items as $gl_item)
161 if ($gl_item->amount < 0)
162 $total += $gl_item->amount;
167 // ------------ common functions
169 function clear_items()
171 unset($this->line_items);
172 $this->line_items = array();
174 unset($this->gl_items);
175 $this->gl_items = array();
180 //--------------------------------------------------------------------------------------------
185 var $item_description;
193 function line_item ($stock_id, $qty, $standard_cost=null, $description=null)
195 $item_row = get_item($stock_id);
197 if ($item_row == null)
198 display_db_error("invalid item added to order : $stock_id", "");
200 $this->mb_flag = $item_row["mb_flag"];
201 $this->units = $item_row["units"];
203 if ($description == null)
204 $this->item_description = $item_row["description"];
206 $this->item_description = $description;
208 if ($standard_cost == null)
209 $this->standard_cost = $item_row["actual_cost"];
211 $this->standard_cost = $standard_cost;
213 $this->stock_id = $stock_id;
214 $this->quantity = $qty;
215 //$this->price = $price;
219 function check_qoh($location, $date_, $reverse)
223 if (!$SysPrefs->allow_negative_stock())
225 if (has_stock_holding($this->mb_flag))
227 $quantity = $this->quantity;
229 $quantity = -$this->quantity;
234 $qoh = get_qoh_on_date($this->stock_id, $location, $date_);
235 if ($quantity + $qoh < 0)
246 //---------------------------------------------------------------------------------------
258 function gl_item($code_id, $dimension_id, $dimension2_id, $amount, $reference,
261 //echo "adding $index, $code_id, $dimension_id, $amount, $reference<br>";
263 if ($description == null)
264 $this->description = get_gl_account_name($code_id);
266 $this->description = $description;
268 $this->code_id = $code_id;
269 $this->dimension_id = $dimension_id;
270 $this->dimension2_id = $dimension2_id;
271 $this->amount = $amount;
272 $this->reference = $reference;
276 //---------------------------------------------------------------------------------------