~sahana-relief-team/sahana-relief-experiments/relief-exp

« back to all changes in this revision

Viewing changes to mod/ims/add_item_db.inc

  • Committer: turtle
  • Date: 2009-11-10 23:51:44 UTC
  • Revision ID: turtle@turtle-laptop-20091110235144-lvhvgwfm053jvq5q
first relief codebase

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
* Sahana Inventory Management System 
 
4
*
 
5
* PHP version 4 and 5
 
6
*
 
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
 
10
*
 
11
* @author        Mahesh Kaluarachchi <mahesh@opensource.lk>
 
12
* @copyright    Lanka Software Foundation - http://www.opensource.lk
 
13
* @package        Sahana
 
14
* @subpackage    
 
15
* @tutorial        
 
16
* @license          http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL)
 
17
*/
 
18
 
 
19
global $global;
 
20
 
 
21
include_once ("add_item.inc");    
 
22
include_once ("errors.inc");
 
23
include_once ('lib_ims.inc');
 
24
 
 
25
 
 
26
function _shn_ims_add_item_db()
 
27
{
 
28
        
 
29
    global $global;
 
30
    $db = $global["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']);
 
40
 
 
41
    
 
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;
 
47
    $predict_amount = 0;
 
48
 
 
49
        
 
50
    $state = "available";
 
51
 
 
52
    $q = "SELECT * FROM ims_item_records;";
 
53
    $ims = $db->Execute($q);
 
54
    if ($ims == NULL) {
 
55
        add_error(SHN_ERR_IMS_ITEM_TABLE_EXISTS);
 
56
        
 
57
    } else {
 
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);
 
60
      
 
61
    _shn_ims_expire_date_check();
 
62
    add_confirmation($item . _t(' Item was successfully added'));
 
63
 
 
64
    $_POST['item_name'] = "";
 
65
    $_POST['amount'] = "";
 
66
    $_POST['cost_per_unit'] = "";
 
67
    $_POST['manufactured_date'] = "";
 
68
    $_POST['expire_date'] = "";
 
69
    }
 
70
    shn_ims_add_item_main_page();
 
71
    
 
72
        
 
73
}
 
74
 
 
75
function _shn_ims_validate_additemform()
 
76
{
 
77
    global $global;
 
78
    $error_flag = false;
 
79
    //clean_errors();
 
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']);
 
87
 
 
88
      
 
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);
 
92
        $error_flag = true;
 
93
    }
 
94
    if ($amount == null || $amount < 0) {
 
95
        add_error(SHN_ERR_IMS_AMOUNT_INCOMPLETE);
 
96
        $error_flag = true;
 
97
    }
 
98
    if ($amount != NULL) {
 
99
        if (!is_numeric($amount)) {
 
100
            add_error(SHN_ERR_IMS_ENTER_NUMERIC_VALUE);
 
101
            $error_flag = true;
 
102
        }
 
103
    }
 
104
 
 
105
    if ($unit == null) {
 
106
        add_error(SHN_ERR_IMS_UNIT_INCOMPLETE);
 
107
        $error_flag = true;
 
108
    }
 
109
 
 
110
    if (trim($_POST['inv_id']) == null) {
 
111
        add_error(SHN_ERR_IMS_INVENTORY_INCOMPLETE);
 
112
        $error_flag = true;
 
113
    }
 
114
    
 
115
    $cost_per_unit = trim($_POST['cost_per_unit']);
 
116
    
 
117
    if ($cost_per_unit != null) {
 
118
        if (!is_numeric($cost_per_unit)) {
 
119
            add_error(SHN_ERR_IMS_ENTER_NUMERIC_VALUE_COST);
 
120
            $error_flag = true;
 
121
        }
 
122
    }
 
123
    
 
124
    if ($cost_per_unit < 0) {
 
125
        add_error(SHN_ERR_IMS_INVALID_COST_PER_UNIT);
 
126
        $error_flag = true;
 
127
    }
 
128
    
 
129
    if (!shn_valid_date($manufactured_date) || !shn_valid_date($expire_date)) {
 
130
        $error_flag = true;
 
131
    }
 
132
 
 
133
    if ($manufactured_date != null || $expire_date != null) {
 
134
        if (_shn_ims_date_validate($manufactured_date)) {
 
135
            $error_flag = true;
 
136
        }
 
137
    
 
138
        if (_shn_ims_date_validate($expire_date)) {
 
139
            $error_flag = true;
 
140
        }
 
141
       _shn_ims_count_days($manufactured_date,$expire_date);       
 
142
    }
 
143
    
 
144
 
 
145
    return $error_flag;
 
146
}
 
147
?>