3
* Sahana Inventory Management System
7
* LICENSE: This source file is subject to LGPL license
8
* that is available through the world-wide-web at the following URI:
9
* http://www.gnu.org/copyleft/lesser.html
11
* @author Mahesh Kaluarachchi <mahesh@opensource.lk>
12
* @copyright Lanka Software Foundation - http://www.opensource.lk
16
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL)
21
include_once ("add_item.inc");
22
include_once ("errors.inc");
23
include_once ('lib_ims.inc');
26
function _shn_ims_add_item_db()
31
$item = trim($_POST['item_name']);
32
$suplier_id = trim($_POST['suplier_id']);
33
$parent_id = trim($_POST['parent_id']);
34
$amou = trim($_POST['amount']);
35
$cost_per_unit = trim($_POST['cost_per_unit']);
36
$unit = trim($_POST['unit_select']);
37
$inv_id = trim($_POST['inv_id']);
38
$manufactured_date = trim($_POST['manufactured_date']);
39
$expire_date = trim($_POST['expire_date']);
42
$date = date("Y-m-d");
43
$total_amount = _shn_ims_sum_amount($parent_id,$inv_id);
44
$base_unit = convert_to_base_unit($unit);
45
$converted_amount = $amou*unit_converter($base_unit,$unit);
46
$total_amount = $total_amount + $converted_amount;
52
$q = "SELECT * FROM ims_item_records;";
53
$ims = $db->Execute($q);
55
add_error(SHN_ERR_IMS_ITEM_TABLE_EXISTS);
58
$sql = " INSERT INTO ims_item_records (catalog_id,inv_id,suplier_id,item_name,amount,cost_per_unit,unit,manufactured_date,expire_date,state,inserted_date,total_amount,predict_amount) VALUES ('$parent_id','$inv_id','$suplier_id','$item','$amou','$cost_per_unit','$unit','$manufactured_date','$expire_date','$state','$date','$total_amount','$predeict_amount');";
59
$ims = $db->Execute($sql);
61
_shn_ims_expire_date_check();
62
add_confirmation($item . _t(' Item was successfully added'));
64
$_POST['item_name'] = "";
65
$_POST['amount'] = "";
66
$_POST['cost_per_unit'] = "";
67
$_POST['manufactured_date'] = "";
68
$_POST['expire_date'] = "";
70
shn_ims_add_item_main_page();
75
function _shn_ims_validate_additemform()
80
$item_name = trim($_POST['item_name']);
81
$parent_id = trim($_POST['parent_id']);
82
$amount = trim($_POST['amount']);
83
$manufactured_date = trim($_POST['manufactured_date']);
84
$expire_date = trim($_POST['expire_date']);
85
$cost_per_unit = trim($_POST['cost_per_unit']);
86
$unit = trim($_POST['unit_select']);
89
//this checks whether name entered in the add main form
90
if ($item_name == null) {
91
add_error(SHN_ERR_IMS_ITEM_NAME_INCOMPLETE);
94
if ($amount == null || $amount < 0) {
95
add_error(SHN_ERR_IMS_AMOUNT_INCOMPLETE);
98
if ($amount != NULL) {
99
if (!is_numeric($amount)) {
100
add_error(SHN_ERR_IMS_ENTER_NUMERIC_VALUE);
106
add_error(SHN_ERR_IMS_UNIT_INCOMPLETE);
110
if (trim($_POST['inv_id']) == null) {
111
add_error(SHN_ERR_IMS_INVENTORY_INCOMPLETE);
115
$cost_per_unit = trim($_POST['cost_per_unit']);
117
if ($cost_per_unit != null) {
118
if (!is_numeric($cost_per_unit)) {
119
add_error(SHN_ERR_IMS_ENTER_NUMERIC_VALUE_COST);
124
if ($cost_per_unit < 0) {
125
add_error(SHN_ERR_IMS_INVALID_COST_PER_UNIT);
129
if (!shn_valid_date($manufactured_date) || !shn_valid_date($expire_date)) {
133
if ($manufactured_date != null || $expire_date != null) {
134
if (_shn_ims_date_validate($manufactured_date)) {
138
if (_shn_ims_date_validate($expire_date)) {
141
_shn_ims_count_days($manufactured_date,$expire_date);