3
/**Internal Library of the 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 Ravindra De Silva <ravindra@opensource.lk><ravidesilva@iee.org>
12
* Mahesh Kaluarachchi <mahesh@opensource.lk>
13
* @copyright Lanka Software Foundation - http://www.opensource.lk
19
include_once $global['approot']."/inc/lib_form.inc";
20
include_once $global['approot']."/inc/lib_location.inc";
21
include_once $global['approot'].'/mod/or/lib_or.inc';
22
include_once $global['approot'].'/3rd/phplot/phplot_ims.php';
24
function shn_ims_org_list()
28
$q = "SELECT inv_uuid,inventory_name,parent_id FROM ims_inventory_records ORDER BY inventory_name";
29
$res_org=$db->Execute($q);
31
while(!$res_org==NULL && !$res_org->EOF){
32
$org_list[$res_org->fields[0]]=$res_org->fields[1];
37
function _shn_ims_get_start_loc()
42
$q="SELECT value FROM config WHERE module_id='or' AND confkey='loc_start'";
43
$res=$db->Execute($q);
44
if($res->fields[0]==NULL){
45
return $conf['mod_or_ims_start_loc'];
47
return $res->fields[0];
51
function shn_ims_get_loc_range()
57
$q="SELECT value FROM config WHERE module_id='or' AND confkey='loc_range_start'";
58
$res=$db->Execute($q);
59
if($res->fields[0]==NULL){
60
$loc["start"]=$conf['mod_or_ims_loc_level_start'];
62
$loc["start"]=$res->fields[0];
64
$q="SELECT value FROM config WHERE module_id='or' AND confkey='loc_range_end'";
65
$res=$db->Execute($q);
66
if($res->fields[0]==NULL){
67
$loc["end"]=$conf['mod_or_ims_loc_level_end'];
69
$loc["end"]=$res->fields[0];
74
function _shn_ims_action_change_javascript($change)
77
<script type="text/javascript">
78
function change_action(action){
79
var x=document.getElementsByName("<?php echo $change?>");
81
document.view.submit();
88
function _shn_ims_admin_javascript($name)
91
<script type="text/javascript">
93
// sort function - ascending (case-insensitive)
94
function sortFuncAsc(record1, record2) {
95
var value1 = record1.optText.toLowerCase();
96
var value2 = record2.optText.toLowerCase();
97
if (value1 > value2) return(1);
98
if (value1 < value2) return(-1);
102
// sort function - descending (case-insensitive)
103
function sortFuncDesc(record1, record2) {
104
var value1 = record1.optText.toLowerCase();
105
var value2 = record2.optText.toLowerCase();
106
if (value1 > value2) return(-1);
107
if (value1 < value2) return(1);
111
function sortSelect(selectToSort, ascendingOrder) {
112
if (arguments.length == 1) ascendingOrder = true; // default to ascending sort
114
// copy options into an array
116
for (var loop=0; loop<selectToSort.options.length; loop++) {
117
myOptions[loop] = { optText:selectToSort.options[loop].text, optValue:selectToSort.options[loop].value };
121
if (ascendingOrder) {
122
myOptions.sort(sortFuncAsc);
124
myOptions.sort(sortFuncDesc);
127
// copy sorted options from array back to select box
128
selectToSort.options.length = 0;
129
for (var loop=0; loop<myOptions.length; loop++) {
130
var optObj = document.createElement('option');
131
optObj.text = myOptions[loop].optText;
132
optObj.value = myOptions[loop].optValue;
133
selectToSort.options.add(optObj);
137
function add_types(){
138
var y=document.getElementsByName("type");
139
var z=document.getElementsByName("type_abbr");
140
var add=document.getElementsByName("added");
141
var remove=document.getElementsByName("removed");
142
var exist=search(add[0].value,z[0].value,true,y[0].value);
144
alert("The Type Exists,you just added it");
148
var x=document.getElementsByName("<?php echo $name?>");
149
exist=search_select_box(x[0],z[0].value,true,y[0].value);
151
alert("The Type Exists in the DataBase");
154
exist=search(remove[0].value,z[0].value,true,y[0].value);
156
remove[0]=del(remove[0].value,z[0].value);
159
opt = document.createElement("option") ;
160
opt.text = y[0].value ;
161
opt.value = z[0].value ;
162
var k=x[0].options.length;
164
sortSelect(x[0], true) ;
165
add[0].value= add[0].value+":"+z[0].value+"|"+y[0].value;
170
function remove_types(){
171
var x=document.getElementsByName("<?php echo $name?>");
172
removeSelectedOptions(x[0]);
173
sortSelect(x[0], true) ;
176
function hasOptions(obj) {
177
if (obj!=null && obj.options!=null) { return true; }
181
function removeSelectedOptions(from) {
182
if (!hasOptions(from)) { return; }
183
if (from.type=="select-one") {
184
from.options[from.selectedIndex] = null;
187
var add=document.getElementsByName("added");
188
var remove=document.getElementsByName("removed");
189
for (var i=(from.options.length-1); i>=0; i--) {
190
var o=from.options[i];
192
var exist=search(add[0].value,o.value,false);
194
add[0].value=del(add[0].value,o.value);
196
remove[0].value= remove[0].value+":"+o.value+"|"+o.text;
198
from.options[i] = null;
202
from.selectedIndex = -1;
205
function search(arr,value,both,desc){
207
var re = new RegExp(value);
208
var temp = new Array();
209
temp = arr.split(':');
213
for (var i=0; i<temp.length; i++) {
214
var options = new Array();
215
options= temp[i].split('|');
216
var re = new RegExp(value);
217
if (re.test(options[0])) {
221
re = new RegExp(desc);
222
if (re.test(options[1])) {
230
function search_select_box(obj,value,both,desc) {
232
if (!hasOptions(obj)) { return false; }
233
for (var i=0; i<obj.options.length; i++) {
234
var re = new RegExp(value);
235
if (re.test(obj.options[i].value)) {
239
re = new RegExp(desc);
240
if (re.test(obj.options[i].text)) {
248
function del(from,what){
249
var temp = new Array();
250
temp = from.split(':');
255
for (var i=1; i<temp.length; i++) {
256
var options = new Array();
257
options= temp[i].split('|');
258
if(options[0]!=what){
260
from= from+":"+options[0]+"|"+options[1];
270
function _shn_ims_get_org_loc_parents($child)
274
$q="SELECT search_id,name,location.location_id FROM location_details,location WHERE poc_uuid='{$child}' AND location_details.location_id=location.location_id";
275
$res_temp=$db->Execute($q);
277
$final[0]=$res_temp->fields[0];
278
$final[1]=$res_temp->fields[1];
279
$final[2]=$res_temp->fields[2];
281
$bsd_village=$res_temp->fields[0];
282
$loc=split("\.", $bsd_village);
284
for($k=0;$k<count($loc)-1;$k++){
288
$q="SELECT name,location_id FROM location WHERE search_id='$cur'";
289
$res_loc=$db->Execute($q);
290
$temp[1]=$res_loc->fields[0];
291
$temp[2]=$res_loc->fields[1];
296
if($k!=count($loc)-1){
309
function _shn_ims_display_gender($error=false,$value=NULL,$label=NULL)
312
$extra_opts['value']=$value;
313
//$extra_opts['req']=false;
315
//$extra_opts['req']=true;
317
$label=($label==NULL)?_t("Gender:"):$label;
318
shn_form_opt_select('opt_gender',$label,$select_opts,$extra_opts);
320
function _shn_ims_display_org_type($error=false,$multi=false,$value=NULL)
323
$extra_opts['value']=$value;
324
// $extra_opts['req']=false;
326
// $extra_opts['req']=true;
328
$extra_opts['req']=true;
330
$select_opts="multiple='true'";
332
//$select_opts="multiple='false'";;
334
shn_form_opt_select('inventory_type','',$select_opts,$extra_opts);
337
function _shn_ims_display_sector($error=false,$value=NULL)
340
$extra_opts['value']=$value;
341
// $extra_opts['req']=false;
343
// $extra_opts['req']=true;
345
$extra_opts['req']=true;
346
shn_form_opt_multi_select('opt_sector_type','','multiple="true"',$extra_opts);
349
function _shn_ims_display_contact_person($error=false,$org=true,$po_uuid=null)
351
if(!shn_is_null($po_uuid)){
354
$q = "SELECT address FROM location_details WHERE poc_uuid='{$po_uuid}'";
355
$res_addr=$db->Execute($q);
356
$contact_address=$res_addr->fields[0];
357
$q = "SELECT contact_value FROM contact WHERE pgoc_uuid='{$po_uuid}' AND opt_contact_type='curr'";
358
$res_phone=$db->Execute($q);
359
$contact_phone=$res_phone->fields[0];
360
$q = "SELECT contact_value FROM contact WHERE pgoc_uuid='{$po_uuid}' AND opt_contact_type='pmob'";
361
$res_mobile=$db->Execute($q);
362
$contact_mobile=$res_mobile->fields[0];
364
$q = "SELECT contact_value FROM contact WHERE pgoc_uuid='{$po_uuid}' AND opt_contact_type='name'";
365
$res_name=$db->Execute($q);
366
$contact_name=$res_name->fields[0];
368
$q = "SELECT contact_value FROM contact WHERE pgoc_uuid='{$po_uuid}' AND opt_contact_type='fax'";
369
$res_fax=$db->Execute($q);
370
$contact_fax=$res_fax->fields[0];
371
$q = "SELECT contact_value FROM contact WHERE pgoc_uuid='{$po_uuid}' AND opt_contact_type='email'";
372
$res_email=$db->Execute($q);
373
$contact_email=$res_email->fields[0];
374
$q = "SELECT contact_value FROM contact WHERE pgoc_uuid='{$po_uuid}' AND opt_contact_type='web'";
375
$res_web=$db->Execute($q);
376
$contact_web=$res_web->fields[0];
379
$extra_opts['value']=$contact_name;
380
shn_form_text(_t("Name : "),'contact_name','size="50"',$extra_opts);
382
$extra_opts['value']=$contact_address;
383
shn_form_text(_t("Address : "),'contact_add','size="50"',$extra_opts);
384
$extra_opts['value']=$contact_phone;
385
shn_form_text(_t("Phone : "),'contact_phone','size="50"',$extra_opts);
386
$extra_opts['value']=$contact_mobile;
387
shn_form_text(_t("Mobile No : "),'contact_mobile','size="50"',$extra_opts);
388
$extra_opts['value']=$contact_fax;
389
shn_form_text(_t("Fax : "),'contact_fax','size="50"',$extra_opts);
390
$extra_opts['value']=$contact_email;
391
shn_form_text(_t("Email : "),'contact_mail','size="50"',$extra_opts);
392
$extra_opts['value']=$contact_web;
393
shn_form_text(_t("Website : "),'contact_web','size="50"',$extra_opts);
396
function _shn_ims_display_org_facilities($error=false,$org_id=false)
398
if(!shn_is_null($org_id)){
401
$q = "SELECT man_power,equipment,resources,space FROM ims_inventory_records WHERE inv_uuid='{$org_id}'";
402
$res_org=$db->Execute($q);
403
if(!$res_org==NULL && !$res_org->EOF){
404
$man_power=$res_org->fields[0];
405
$equipment=$res_org->fields[1];
406
$resources=$res_org->fields[2];
407
$space=$res_org->fields[3];
410
$extra_opts['value']=$man_power;
411
shn_form_text(_t("Man Power : "),'man_power','size="50"',$extra_opts);
412
$extra_opts['value']=$equipment;
413
shn_form_text(_t("Equipment : "),'equipment','size="50"',$extra_opts);
414
$extra_opts['value']=$resources;
415
shn_form_text(_t("Other relevant resources : "),'resources','size="50"',$extra_opts);
416
$extra_opts['value']=$space;
417
shn_form_text(_t("Inventory Space : "),'space','size="50"',$extra_opts);
421
function _shn_ims_display_logininfo($error=false)
423
// for get login info
425
array('desc'=>_t("Account Name : "),'type'=>"text",'size'=>20,'name'=>'account_name','br'=>1),
426
array('desc'=>_t("* User Name for Login: "),'type'=>"text",'size'=>20,'name'=>'user_name','br'=>1),
427
array('desc'=>_t("* Password for Login: "),'type'=>"password",'size'=>20,'name'=>'password','br'=>1),
428
array('desc'=>_t("* Confirm Password: "),'type'=>"password",'size'=>20,'name'=>'re_password','br'=>1)
429
); // end of getting logging info
433
function _shn_ims_display_extra($error=false)
435
shn_form_checkbox(_t("Add Operation<br> (Your Organization might be having branches or carrying out relief operations in this disaster. Then information of those operations is useful : )"),'chk_branch',null,$chkbox_opts);
438
//-----------------------------------------------------------------------------------------------------------------
439
function _shn_ims_expire_date_check()
446
$sql="UPDATE ims_item_records SET state='$state' WHERE ((TO_DAYS(expire_date) - TO_DAYS(CURRENT_DATE()))<0 and state!='$state1');";
447
$ims=$db->Execute($sql);
450
function _shn_ims_date_validate($date)
455
list($year,$month,$day)=split('[/.-]', $date);
456
if($year<0 || $year>2100 )
458
//add_error("Year should be a value between 1900 and 2100");
461
if($month<0 || $month>12 )
463
//add_error("Invalid Month");
468
//add_error("Invald Day");
471
if(($month==1 || $month==3 || $month==5 || $month==7 || $month==8 || $month==10 || $month==12) && $day>31)
473
//add_error("The month doesn't have such a date ");
476
if($month==2 && $day>29)
478
//add_error(SHN_ERR_IMS_INVALID_DATE);
481
if(($month==4 || $month==6 || $month==9 || $month==11) && $day>30)
483
//add_error("The month doesn't have such a date ");
487
if($error_flag1==true)
489
add_error(SHN_ERR_IMS_INVALID_DATE);
498
function _shn_ims_find_catalogid($catalog_id)
502
$catalog_found=false;
503
$sql1="SELECT item_id FROM ims_item_records WHERE catalog_id='$catalog_id';";
504
$ims1=$db->Execute($sql1);
505
$item_id=$ims1->fields['item_id'];
508
$sql2="SELECT inv_id FROM ims_reorder_level WHERE catalog_id='$catalog_id';";
509
$ims2=$db->Execute($sql2);
510
$inv_id=$ims2->fields['inv_id'];
512
if($item_id!=null || $inv_id!=null)
518
$catalog_found=false;
521
return $catalog_found;
524
function _shn_ims_find_unitid($unit_id)
530
$sql1="SELECT item_id FROM ims_item_records WHERE unit='$unit_id';";
531
$ims1=$db->Execute($sql1);
532
$item_id=$ims1->fields['item_id'];
535
$sql2="SELECT inv_id FROM ims_reorder_level WHERE unit='$unit_id';";
536
$ims2=$db->Execute($sql2);
537
$inv_id=$ims2->fields['inv_id'];
539
$sql3="SELECT item_id FROM ims_transfer_item WHERE unit='$unit_id';";
540
$ims3=$db->Execute($sql3);
541
$item_id3=$ims3->fields['item_id'];
543
if($item_id!=null || $inv_id!=null || $item_id3!=null)
557
* Returns an array ready of names and locations ready to be
559
* @global <type> $global
560
* @global <type> $conf
561
* @param <type> $inv_id
564
function _shn_ims_gis_inv($inv_id)
569
require_once $global['approot'] . "/inc/lib_gis/gis_fns.inc";
571
$sql1 = "SELECT * FROM ims_inventory_records;";
573
$sql1 = "SELECT * FROM ims_inventory_records WHERE inv_uuid = '$inv_id';";
575
$ims1 = $db->Execute($sql1);
576
$ims1=$db->Execute($sql1);
578
while(!$ims1==NULL && !$ims1->EOF){
580
$gis_result = shn_gis_get_features_item_ref($ims1->fields['inv_uuid'], array('f_coords' => '1', 'f_url' => '1'));
582
// decode coords from str -> array of x y z
583
$coords = shn_gis_coord_decode($gis_result[0]['f_coords']);
584
array_push($map_array,array("lat"=>$coords[0][0],"lon"=>$coords[0][1],"name"=>$ims1->fields['inventory_name'],"id"=>$ims2->fields['poc_uuid'],"url"=>"mod=ims&act=view_inv&id={$ims1->fields['inv_uuid']}"));
591
function _shn_ims_get_location($inv_id)
596
$sql1="SELECT * FROM location_details WHERE poc_uuid='$inv_id';";
597
$ims1=$db->Execute($sql1);
599
$location_id=$ims1->fields['location_id'];
602
$string_array=array();
605
while($location_id!=NULL)
607
$sql2="SELECT * FROM location WHERE loc_uuid='$location_id';";
608
$ims2=$db->Execute($sql2);
609
$parent_id=$ims2->fields['parent_id'];
610
$name=$ims2->fields['name'];
611
//array_push($string_array,$location_id=>$name);
612
$string_array[$i]=$name;
615
$location_id=$parent_id;
618
for($j=$i-2;$j>=0;$j--)
621
$string=$string_array[$j];
628
$location=$location."->".$string;
636
//*******************************************************SOC*******************************************************
637
function _shn_ims_date_conversion($date)
639
list($year,$month,$day) = split("-",$date);
640
$convert_date=$month."-".$day."-".$year;
641
return $convert_date;
643
function _shn_ims_count_days($start, $end)
645
$string1=explode("-",$start);
646
$string2=explode("-",$end);
647
$numStart=mktime(0,0,0,$string1[1],$string1[2],$string1[0]);
648
$numEnd=mktime(0,0,0,$string2[1],$string2[2],$string2[0]);
650
if( $start != '0000-00-00' and $end != '0000-00-00' )
652
/*$timestamp_start = strtotime($start);
653
$timestamp_end = strtotime($end);
654
if( $timestamp_start >= $timestamp_end ) return 0;
655
$start_year = date("Y",$timestamp_start);
656
$end_year = date("Y", $timestamp_end);*/
657
//$num_days_end = date("z",strtotime($start));
658
//$num_days_end = date("z", strtotime($end));
659
if($numEnd<$numStart){
660
add_error(SHN_ERR_IMS_MANU_DATE_GRT_EX_DATE_INVALID);
664
$s=mktime(0,0,0,date(m),date(d),date(Y));
666
add_error(SHN_ERR_IMS_CUR_DATE_GRT_EX_DATE_INVALID);
670
add_error(SHN_ERR_IMS_MANU_DATE_GRT_CUR_DATE_INVALID);
676
if( $end_year > $start_year )
678
while( $i < ( $end_year - $start_year ) )
680
$num_days = $num_days + date("z", strtotime(($start_year + $i)."-12-31"));
684
return ( $num_days_end + $num_days ) - $num_days_start;
692
function _shn_ims_smoothing($forcasted_value,$actual_value,$alpha)
697
$forcast_value=((1-$alpha)*$forcasted_value)+($alpha*$actual_value);
698
return $forcast_value;
702
function _shn_ims_datediff($dformat, $endDate, $beginDate)
704
$date_parts1=explode($dformat, $beginDate);
705
$date_parts2=explode($dformat, $endDate);
706
$start_date=gregoriantojd($date_parts1[0], $date_parts1[1], $date_parts1[2]);
707
$end_date=gregoriantojd($date_parts2[0], $date_parts2[1], $date_parts2[2]);
708
return $end_date - $start_date;
712
function _shn_ims_total_amount($catalog_id,$inv_id)
719
$sql1="SELECT * FROM ims_item_records WHERE inv_id='$inv_id' AND catalog_id='$catalog_id';";
720
$ims1=$db->Execute($sql1);
722
while(!$ims1==NULL && !$ims1->EOF)
724
$amount=$ims2->fields['amount'];
725
$unit=$ims2->fields['unit'];
727
$base_unit=convert_to_base_unit($unit);
728
$converted_amount=$amount*unit_converter($base_unit,$unit);
730
$sum_amount=$sum_amount + $converted_amount;
741
function _shn_ims_sum_amount($catalog_id,$inv_id)
747
$sql1="SELECT * FROM ims_item_records WHERE catalog_id='$catalog_id';";
748
$ims1=$db->Execute($sql1);
752
$sql1="SELECT * FROM ims_item_records WHERE inv_id='$inv_id' AND catalog_id='$catalog_id';";
753
$ims1=$db->Execute($sql1);
756
while(!$ims1==NULL && !$ims1->EOF)
758
$amount=$ims1->fields['amount'];
759
$unit=$ims1->fields['unit'];
761
$base_unit=convert_to_base_unit($unit);
762
$converted_amount=$amount*unit_converter($base_unit,$unit);
764
$sum_amount=$sum_amount + $converted_amount;
770
function _shn_ims_first_data($inv_id,$catalog_id)
774
$sql1="SELECT * FROM ims_inventory_records WHERE inv_uuid='$inv_id';";
775
$ims1=$db->Execute($sql1);
776
$date_inv=$ims1->fields['added_date'];
777
$date_inv_convert=_shn_ims_date_conversion($date_inv);
778
//has to be commented
779
$date_inv_convert="01-08-2006";
781
$current_date=date("m-d-Y");
782
$number_of_days=_shn_ims_datediff('-',$current_date,$date_inv_convert);
783
$temp=$number_of_days-7;
786
$days_after_inv_date=date("Y-m-d",time() - ($temp*24*60*60));
790
$days_after_inv_date=date("Y-m-d",time() -($number_of_days*24*60*60));
794
$sql2="SELECT * FROM ims_item_records WHERE catalog_id='$catalog_id' AND inv_id='$inv_id' AND (TO_DAYS(inserted_date) - TO_DAYS($date_inv))<7;";
795
$ims2=$db->Execute($sql2);
797
while(!$ims2==NULL && !$ims2->EOF)
799
$amount=$ims1->fields['amount'];
800
$unit=$ims1->fields['unit'];
802
$base_unit=convert_to_base_unit($unit);
803
$converted_amount=$amount*unit_converter($base_unit,$unit);
805
$sum_amount=$sum_amount + $converted_amount;
808
//return $sum_amount;
809
//$week=date("d-m-Y",time() + 604800);
810
//$date_amount_inv=date("Y-m-d",time() - 604800);
811
//$date_inv_week=_shn_ims_datediff('-',$date_inv_week,$date);
815
function _shn_ims_smoothing_constant($catalog_id,$inv_id)
820
$sql1="SELECT * FROM ims_optimization WHERE catalog_id='$catalog_id' AND inv_id='$inv_id' ORDER BY week DESC;";
821
$ims1=$db->Execute($sql1);
823
$week=$ims1->fields['week'];
832
function _shn_ims_weekafter($fyear, $fmonth, $fday)
834
return date ("Y-m-d", mktime (0,0,0,$fmonth,$fday+7,$fyear));
837
function _shn_ims_timeafter($fyear, $fmonth, $fday,$time_period)
839
return date ("Y-m-d", mktime (0,0,0,$fmonth,$fday+$time_period,$fyear));
842
function _shn_ims_insert_data_to_predict($catalog_id,$inv_id,$time_period)
847
$sql1="SELECT * FROM ims_inventory_records WHERE inv_uuid='$inv_id';";
848
$ims1=$db->Execute($sql1);
849
$date_inv=$ims1->fields['added_date'];
850
$date_inv_convert=_shn_ims_date_conversion($date_inv);
851
$current_date=date("Y-m-d");
854
$date_diff=_shn_ims_count_days($date_inv,$current_date);
856
$item_state_destroyed="destroyed";
858
for($i=$date_diff;$i>=0;$i-=$time_period)
859
//while(_shn_ims_count_days($date_inv,$current_date)<1 && _shn_ims_count_days($date_inv,$current_date)>0 )
861
$date_inv_temp=$date_inv;
862
//$sql2="SELECT * FROM ims_item_records WHERE inv_id='$inv_id' AND catalog_id='$catalog_id' AND (TO_DAYS(inserted_date) - TO_DAYS($date_inv_temp))<7;";
863
$sql2="SELECT * FROM ims_item_records WHERE inv_id='$inv_id' AND catalog_id='$catalog_id' AND state!='$item_state_destroyed';";
864
$ims2=$db->Execute($sql2);
868
while(!$ims2==NULL && !$ims2->EOF)
870
$amount=$ims2->fields['amount'];
872
$unit=$ims2->fields['unit'];
873
$inserted_date=$ims2->fields['inserted_date'];
875
if(_shn_ims_count_days($date_inv_temp,$current_date)<_shn_ims_count_days($inserted_date,$current_date)||_shn_ims_count_days($date_inv_temp,$current_date)==_shn_ims_count_days($inserted_date,$current_date))
878
$base_unit=convert_to_base_unit($unit);
879
$converted_amount=$amount*unit_converter($base_unit,$unit);
881
$sum_amount=$sum_amount + $converted_amount;
882
$sum_amount_temp=$sum_amount;
886
$sum_amount_temp=$sum_amount;
890
$actual_value=$sum_amount_temp;
900
$forecasted_value_temp=_shn_ims_smoothing($forecasted_value,$actual_value,$alpha);
905
//$alpha_smoothing=1-$alpha;
906
$forecasted_value=_shn_ims_smoothing($forecasted_value,$actual_value,$alpha);
907
//$actual_value_smoothing=$alpha*$actual_value;
908
//$forecasted_value_smoothing=$alpha_smoothing*$forcasted_value;
909
//$forecasted_value=$forecasted_value_smoothing + $actual_value_smoothing;
912
$sql3="INSERT INTO ims_optimization (catalog_id,inv_id,week,actual_value,forecasted_value,unit) VALUES ('$catalog_id','$inv_id','$week','$sum_amount_temp','$forecasted_value','$base_unit');";
913
$ims3=$db->Execute($sql3);
915
list($year,$month,$day) = split("-",$date_inv);
916
$date_inv=_shn_ims_timeafter($year, $month, $day,$time_period);
920
$forecasted_value=$forecasted_value_temp;
930
function _shn_ims_predict_sending_items($catalog_id,$inv_id,$time_period)
935
$sql1="SELECT * FROM ims_inventory_records WHERE inv_uuid='$inv_id';";
936
$ims1=$db->Execute($sql1);
937
$date_inv=$ims1->fields['added_date'];
938
$date_inv_convert=_shn_ims_date_conversion($date_inv);
939
$current_date=date("Y-m-d");
942
$date_diff=_shn_ims_count_days($date_inv,$current_date);
944
$item_state_destroyed="destroyed";
946
for($i=$date_diff;$i>=0;$i-=$time_period)
947
//while(_shn_ims_count_days($date_inv,$current_date)<1 && _shn_ims_count_days($date_inv,$current_date)>0 )
949
$date_inv_temp=$date_inv;
950
//$sql2="SELECT * FROM ims_item_records WHERE inv_id='$inv_id' AND catalog_id='$catalog_id' AND (TO_DAYS(inserted_date) - TO_DAYS($date_inv_temp))<7;";
951
$sql2="SELECT * FROM ims_transfer_item WHERE inv_id_from='$inv_id' AND catalog_id='$catalog_id';";
952
$ims2=$db->Execute($sql2);
958
while(!$ims2==NULL && !$ims2->EOF)
960
$amount=$ims2->fields['amount_send'];
962
$unit=$ims2->fields['unit'];
963
$inserted_date=$ims2->fields['date_send'];
965
if(_shn_ims_count_days($date_inv_temp,$current_date)==_shn_ims_count_days($inserted_date,$current_date))
968
$base_unit=convert_to_base_unit($unit);
969
$converted_amount=$amount*unit_converter($base_unit,$unit);
971
$sum_amount=$sum_amount + $converted_amount;
972
$sum_amount_temp=$sum_amount;
976
$sum_amount_temp=$sum_amount;
980
$actual_value=$sum_amount_temp;
991
$forecasted_value_temp=_shn_ims_smoothing($forecasted_value,$actual_value,$alpha);
996
$forecasted_value=_shn_ims_smoothing($forecasted_value,$actual_value,$alpha);
1000
$sql3="INSERT INTO ims_optimization (catalog_id,inv_id,week,actual_value,forecasted_value,unit) VALUES ('$catalog_id','$inv_id','$week','$sum_amount_temp','$forecasted_value','$base_unit');";
1001
$ims3=$db->Execute($sql3);
1004
list($year,$month,$day) = split("-",$date_inv);
1005
$date_inv=_shn_ims_timeafter($year, $month, $day,$time_period);
1009
$forecasted_value=$forecasted_value_temp;
1019
function _shn_ims_predict_receiving_items($catalog_id,$inv_id,$time_period)
1025
$sql1="SELECT * FROM ims_inventory_records WHERE inv_uuid='$inv_id';";
1026
$ims1=$db->Execute($sql1);
1027
$date_inv=$ims1->fields['added_date'];
1028
$date_inv_convert=_shn_ims_date_conversion($date_inv);
1029
$current_date=date("Y-m-d");
1032
$date_diff=_shn_ims_count_days($date_inv,$current_date);
1034
$received_item_id=-1;
1036
$item_state_destroyed="destroyed";
1038
for($i=$date_diff;$i>=0;$i-=$time_period)
1039
//while(_shn_ims_count_days($date_inv,$current_date)<1 && _shn_ims_count_days($date_inv,$current_date)>0 )
1041
$date_inv_temp=$date_inv;
1043
$sql2="SELECT * FROM ims_transfer_item WHERE inv_id_to='$inv_id' AND catalog_id='$catalog_id' AND received_item_id!='$received_item_id';";
1044
$ims2=$db->Execute($sql2);
1047
while(!$ims2==NULL && !$ims2->EOF)
1049
$amount=$ims2->fields['amount_received'];
1051
$unit=$ims2->fields['unit'];
1052
$inserted_date=$ims2->fields['date_received'];
1055
if(_shn_ims_count_days($date_inv_temp,$current_date)==_shn_ims_count_days($inserted_date,$current_date))
1058
$base_unit=convert_to_base_unit($unit);
1059
$converted_amount=$amount*unit_converter($base_unit,$unit);
1061
$sum_amount=$sum_amount + $converted_amount;
1062
$sum_amount_temp=$sum_amount;
1066
$sum_amount_temp=$sum_amount;
1070
$actual_value=$sum_amount_temp;
1079
$forecasted_value=0;
1081
$forecasted_value_temp=_shn_ims_smoothing($forecasted_value,$actual_value,$alpha);
1086
$forecasted_value=_shn_ims_smoothing($forecasted_value,$actual_value,$alpha);
1090
$sql3="INSERT INTO ims_optimization (catalog_id,inv_id,week,actual_value,forecasted_value,unit) VALUES ('$catalog_id','$inv_id','$week','$sum_amount_temp','$forecasted_value','$base_unit');";
1091
$ims3=$db->Execute($sql3);
1095
list($year,$month,$day) = split("-",$date_inv);
1096
$date_inv=_shn_ims_timeafter($year, $month, $day,$time_period);
1099
$forecasted_value=$forecasted_value_temp;
1111
function _shn_ims_predict_both_items($catalog_id,$inv_id,$time_period)
1117
$sql1="SELECT * FROM ims_inventory_records WHERE inv_uuid='$inv_id';";
1118
$ims1=$db->Execute($sql1);
1119
$date_inv=$ims1->fields['added_date'];
1120
$date_inv_convert=_shn_ims_date_conversion($date_inv);
1121
$current_date=date("Y-m-d");
1124
$date_diff=_shn_ims_count_days($date_inv,$current_date);
1126
$received_item_id=-1;
1128
$item_state_destroyed="destroyed";
1130
for($i=$date_diff;$i>=0;$i-=$time_period)
1131
//while(_shn_ims_count_days($date_inv,$current_date)<1 && _shn_ims_count_days($date_inv,$current_date)>0 )
1133
$date_inv_temp=$date_inv;
1135
$sql2="SELECT * FROM ims_transfer_item WHERE inv_id_to='$inv_id' AND catalog_id='$catalog_id' AND received_item_id!='$received_item_id';";
1136
$ims2=$db->Execute($sql2);
1140
while(!$ims2==NULL && !$ims2->EOF)
1142
$amount=$ims2->fields['amount_received'];
1144
$unit=$ims2->fields['unit'];
1145
$inserted_date=$ims2->fields['date_received'];
1147
if(_shn_ims_count_days($date_inv_temp,$current_date)<_shn_ims_count_days($inserted_date,$current_date)||_shn_ims_count_days($date_inv_temp,$current_date)==_shn_ims_count_days($inserted_date,$current_date))
1150
$base_unit=convert_to_base_unit($unit);
1151
$converted_amount=$amount*unit_converter($base_unit,$unit);
1153
$sum_amount=$sum_amount + $converted_amount;
1154
$sum_amount_temp=$sum_amount;
1158
$sum_amount_temp=$sum_amount;
1162
$actual_value=$sum_amount_temp;
1168
$forecasted_value=_shn_ims_smoothing($forecasted_value,$actual_value,$alpha);
1170
$sql3="INSERT INTO ims_optimization (catalog_id,inv_id,week,actual_value,forecasted_value,unit) VALUES ('$catalog_id','$inv_id','$week','$sum_amount_temp','$forecasted_value','$base_unit');";
1171
$ims3=$db->Execute($sql3);
1175
list($year,$month,$day) = split("-",$date_inv);
1176
$date_inv=_shn_ims_timeafter($year, $month, $day,$time_period);
1184
function _shn_ims_get_alternate_item_amount($catalog_id,$inv_id)
1186
$item_state="destroyed";
1187
$sql3="SELECT * FROM ims_alternate WHERE catalog_id='$catalog_id' AND inv_id='$inv_id';";
1188
$ims3=$db->Execute($sql3);
1190
while(!$ims3==NULL && !$ims3->EOF)
1192
$alternate=$ims3->fields['alternate'];
1196
$sql4="SELECT * FROM ims_item_records WHERE catalog_id='$alternate' AND state!='$item_state';";
1200
$sql4="SELECT * FROM ims_item_records WHERE catalog_id='$alternate' AND inv_id='$inv_id' AND state!='$item_state';";
1202
$ims4=$db->Execute($sql4);
1204
while(!$ims4==NULL && !$ims4->EOF)
1206
$item_id=$ims4->fields["item_id"];
1207
$suplier_id=$ims4->fields["suplier_id"];
1208
$suplier_name_array=_shn_or_get_suplier_name($suplier_id);
1209
$suplier_name=$suplier_name_array[$suplier_id];
1210
$item_name=$ims4->fields['item_name'];
1212
$inventory_id=$ims4->fields['inv_id'];
1215
$amount=$ims4->fields["amount"];
1218
$unit=$ims4->fields["unit"];
1219
$base_unit=convert_to_base_unit($unit);
1221
$converted_amount=$amount*unit_converter($base_unit,$unit);
1223
$sum_amount=$sum_amount + $converted_amount;
1224
$alternate_sum_amount=$alternate_sum_amount + $converted_amount;
1226
$unit_name=get_unit_name($unit);
1227
$base_unit_name=get_unit_name($base_unit);
1228
$state=$ims->fields['state'];
1231
$sql5="SELECT inventory_name FROM ims_inventory_records WHERE inv_uuid='$inventory_id';";
1232
$ims5=$db->Execute($sql5);
1233
$inventory_name=$ims5->fields['inventory_name'];
1246
function _shn_ims_bar_chart_inventory($data,$catalog_array,$i,$y)
1248
//include ( "../3rd/phplot1/phplot.php");
1249
$graph = new PHPlot(700,500);
1251
//$graph->SetDataType( "linear-linear"); //text-data
1252
$graph->SetDataType("text-data"); //Must be called before SetDataValues
1255
$graph->SetDataValues($data);
1256
$graph->SetFileFormat("png");
1258
$graph->SetImageArea(700,500);
1259
/*commented types are ok with the data*/
1260
//$graph->SetPlotType( "lines");
1261
//$graph->SetPlotType( "linepoints");
1262
//$graph->SetPlotType( "points");
1263
//$graph->SetPlotType( "area");
1264
//$graph->SetPlotType( "thinbarline");
1265
//$graph->SetPlotType( "squared");
1266
//$graph->SetPlotType( "pie");
1267
$graph->SetPlotType( "bars");
1268
//$graph->SetPlotType( "stackedbars");
1270
$graph->SetTitleFontSize( "5"); // the max value of font size is 5
1271
$graph->SetTitle( "Forecasting by Inventory");
1273
$graph->SetLegend($catalog_array);
1274
//$graph->SetPlotAreaWorld(2000,0,2050,2500); // parameters = ($starting_val_of_x_axis, $s_val_of_y, $ending_val_of_x, $e_val_of_y)
1275
$graph->SetPlotBgColor( "red");
1276
$graph->SetPlotBorderType( "left");
1277
$graph->SetBackgroundColor( "orange"); // set the chart background
1279
//you can set the x title by one line or as commented three lines
1280
$graph->SetXTitle("Item", "both"); // para = ($title, $position); $postion= plotup or plotdown or both or none
1281
$graph->SetYTitle('Amount',"both"); // plotright or plotleft or both or both
1284
/*$graph->SetXLabel( "Year");
1285
$graph->SetHorizTickIncrement( "5");
1286
$graph->SetXGridLabelType( "title");*/
1289
$graph->SetVertTickIncrement( "500"); //the gap between two values in the Y axis
1290
$graph->SetPrecisionY( "0"); // determine how many decimal points should be there in Y axis values
1291
$graph->SetYGridLabelType( "data");
1292
$graph->SetLightGridColor( "blue");
1293
$graph->SetOutputFile("barChart.png");
1296
//$graph->SetNewPlotAreaPixels(70,120,375,220);
1297
$graph->SetPlotAreaWorld(0,0,$i,$y);
1298
$graph->DrawGraph();
1306
function _shn_ims_bar_chart($data,$j,$max)
1308
//include ( "../3rd/phplot1/phplot.php");
1309
$graph = new PHPlot(700,500);
1311
//$graph->SetDataType( "linear-linear"); //text-data
1312
$graph->SetDataType("text-data"); //Must be called before SetDataValues
1315
$graph->SetDataValues($data);
1316
$graph->SetFileFormat("png"); // parameters = "png" or "jpg" or "gif"
1318
//Specify plotting area details
1319
$graph->SetImageArea(700,500);
1320
/*commented types are ok with the data*/
1321
//$graph->SetPlotType( "lines");
1322
//$graph->SetPlotType( "linepoints");
1323
//$graph->SetPlotType( "points");
1324
//$graph->SetPlotType( "area");
1325
//$graph->SetPlotType( "thinbarline");
1326
//$graph->SetPlotType( "squared");
1327
//$graph->SetPlotType( "pie");
1328
$graph->SetPlotType( "bars");
1329
//$graph->SetPlotType( "stackedbars");
1331
$graph->SetTitleFontSize( "5"); // the max value of font size is 5
1332
$graph->SetTitle( "Forecasting by item");
1334
$graph->SetLegend(array("actual value","forecasted value"));
1335
//$graph->SetPlotAreaWorld(2000,0,2050,2500); // parameters = ($starting_val_of_x_axis, $s_val_of_y, $ending_val_of_x, $e_val_of_y)
1336
$graph->SetPlotBgColor( "red");
1337
$graph->SetPlotBorderType( "left");
1338
$graph->SetBackgroundColor( "orange"); // set the chart background
1340
//you can set the x title by one line or as commented three lines
1341
$graph->SetXTitle("Time Period", "both"); // para = ($title, $position); $postion= plotup or plotdown or both or none
1342
$graph->SetYTitle('Amount',"both"); // plotright or plotleft or both or both
1345
/*$graph->SetXLabel( "Year");
1346
$graph->SetHorizTickIncrement( "5");
1347
$graph->SetXGridLabelType( "title");*/
1350
$graph->SetVertTickIncrement( "500"); //the gap between two values in the Y axis
1351
$graph->SetPrecisionY( "0"); // determine how many decimal points should be there in Y axis values
1352
$graph->SetYGridLabelType( "data");
1353
$graph->SetLightGridColor( "blue");
1354
$graph->SetOutputFile("barChart.png");
1359
//$graph->SetNewPlotAreaPixels(70,120,375,220);
1360
$graph->SetPlotAreaWorld(0,0,$j,$max);
1361
$graph->DrawGraph();
1364
function _shn_ims_line_chart($data,$x,$y)
1366
$graph = new PHPlot(700,500);
1368
//$graph->SetDataType( "linear-linear"); //text-data
1369
$graph->SetDataType("text-data"); //Must be called before SetDataValues
1371
$graph->SetDataValues($data);
1372
$graph->SetFileFormat("png"); // parameters = "png" or "jpg" or "gif"
1374
//Specify plotting area details
1375
$graph->SetImageArea(700,500);
1376
/*commented types are ok with the data*/
1377
$graph->SetPlotType( "lines");
1378
//$graph->SetPlotType( "linepoints");
1379
//$graph->SetPlotType( "points");
1380
//$graph->SetPlotType( "area");
1381
//$graph->SetPlotType( "thinbarline");
1382
//$graph->SetPlotType( "squared");
1383
//$graph->SetPlotType( "pie");
1384
//$graph->SetPlotType( "bars");
1385
//$graph->SetPlotType( "stackedbars");
1387
$graph->SetTitleFontSize( "5"); // the max value of font size is 5
1388
$graph->SetTitle( "Forecasting by Item");
1390
$graph->SetLegend(array("Re-Order level","forecasted value"));
1391
//$graph->SetPlotAreaWorld(2000,0,2050,2500); // parameters = ($starting_val_of_x_axis, $s_val_of_y, $ending_val_of_x, $e_val_of_y)
1392
$graph->SetPlotBgColor( "red");
1393
$graph->SetPlotBorderType( "left");
1394
$graph->SetBackgroundColor( "orange"); // set the chart background
1396
//you can set the x title by one line or as commented three lines
1397
$graph->SetXTitle("time", "both"); // para = ($title, $position); $postion= plotup or plotdown or both or none
1398
$graph->SetYTitle('amount',"both"); // plotright or plotleft or both or both
1401
/*$graph->SetXLabel( "Year");
1402
$graph->SetHorizTickIncrement( "5");
1403
$graph->SetXGridLabelType( "title");*/
1406
$graph->SetVertTickIncrement( "500"); //the gap between two values in the Y axis
1407
$graph->SetPrecisionY( "0"); // determine how many decimal points should be there in Y axis values
1408
$graph->SetYGridLabelType( "data");
1409
$graph->SetLightGridColor( "blue");
1410
$graph->SetOutputFile("lineChart.png");
1414
//$graph->SetNewPlotAreaPixels(70,120,375,220);
1415
$graph->SetPlotAreaWorld(0,0,$x,$y);
1416
$graph->DrawGraph();
1419
function _shn_ims_pie_chart($data,$catalog_array)
1421
$graph = new PHPlot(700,500);
1423
//$graph->SetDataType( "linear-linear"); //text-data
1424
$graph->SetDataType("text-data"); //Must be called before SetDataValues
1426
$data2 = array($data);
1428
$graph->SetDataValues($data);
1429
$graph->SetFileFormat("png"); // parameters = "png" or "jpg" or "gif"
1431
//Specify plotting area details
1432
$graph->SetImageArea(700,500);
1433
/*commented types are ok with the data*/
1434
//$graph->SetPlotType( "lines");
1435
//$graph->SetPlotType( "linepoints");
1436
//$graph->SetPlotType( "points");
1437
//$graph->SetPlotType( "area");
1438
//$graph->SetPlotType( "thinbarline");
1439
//$graph->SetPlotType( "squared");
1440
$graph->SetPlotType( "pie");
1441
//$graph->SetPlotType( "bars");
1442
//$graph->SetPlotType( "stackedbars");
1444
$graph->SetTitleFontSize( "5"); // the max value of font size is 5
1445
$graph->SetTitle( "Forecasting by Inventory");
1447
//$graph->SetLegend(array("2000","2001","2002","2003", "2004", "2005", "2006", "2007"));
1448
$graph->SetLegend($catalog_array);
1449
//$graph->SetPlotAreaWorld(2000,0,2050,2500); // parameters = ($starting_val_of_x_axis, $s_val_of_y, $ending_val_of_x, $e_val_of_y)
1450
$graph->SetPlotBgColor( "red");
1451
$graph->SetPlotBorderType( "left");
1452
$graph->SetBackgroundColor( "orange"); // set the chart background
1454
//you can set the x title by one line or as commented three lines
1455
//$graph->SetXTitle("SD X title", "both"); // para = ($title, $position); $postion= plotup or plotdown or both or none
1456
//$graph->SetYTitle('SD Y title',"both"); // plotright or plotleft or both or both
1459
/*$graph->SetXLabel( "Year");
1460
$graph->SetHorizTickIncrement( "5");
1461
$graph->SetXGridLabelType( "title");*/
1464
$graph->SetVertTickIncrement( "500"); //the gap between two values in the Y axis
1465
$graph->SetPrecisionY( "0"); // determine how many decimal points should be there in Y axis values
1466
$graph->SetYGridLabelType( "data");
1467
$graph->SetLightGridColor( "blue");
1468
$graph->SetOutputFile("pieChart.png");
1471
//$graph->SetNewPlotAreaPixels(70,120,375,220);
1472
$graph->SetPlotAreaWorld(0,0,7,2000);
1473
$graph->DrawGraph();
1478
function _shn_ims_chart_test()
1480
$graph = new PHPlot(700,500);
1482
//$graph->SetDataType( "linear-linear"); //text-data
1483
$graph->SetDataType("text-data"); //Must be called before SetDataValues
1486
array( "a", 2000,1500),
1487
array( "b", 2010,1000),
1488
array( "c", 2015,500),
1489
array( "dd",2020,2000),
1490
array( "e", 2025,100),
1491
//array( "f", 2030,50),
1492
// array( "f", 2030,50),
1493
//array( "f", 2030,50)
1496
// Specify some data
1498
array( "a", 2000,1500, 0, 100, 600,200),
1499
array( "b", 2010,1000, 100, 150,200,300),
1500
array( "c", 2015,500, 700, 179, 400,500),
1501
array( "d",2020,200,1000,979, 1000,600),
1502
array( "e", 2025,100,1200,78,150,700),
1503
array( "f", 2030,50, 1450,343, 1300,800)
1504
// array( "g", 2030,50, 1450,343, 1300,800),
1505
//array( "h", 2030,50, 1450,343, 1300,800)
1507
$graph->SetDataValues($data);
1508
$graph->SetFileFormat("png"); // parameters = "png" or "jpg" or "gif"
1510
//Specify plotting area details
1511
$graph->SetImageArea(700,500);
1512
/*commented types are ok with the data*/
1513
//$graph->SetPlotType( "lines");
1514
//$graph->SetPlotType( "linepoints");
1515
//$graph->SetPlotType( "points");
1516
//$graph->SetPlotType( "area");
1517
//$graph->SetPlotType( "thinbarline");
1518
//$graph->SetPlotType( "squared");
1519
//$graph->SetPlotType( "pie");
1520
$graph->SetPlotType( "bars");
1521
//$graph->SetPlotType( "stackedbars");
1523
$graph->SetTitleFontSize( "5"); // the max value of font size is 5
1524
$graph->SetTitle( "This is SD test chart");
1526
$graph->SetLegend(array("2000","2001","2002","2003", "2004", "2005", "2006", "2007"));
1527
//$graph->SetPlotAreaWorld(2000,0,2050,2500); // parameters = ($starting_val_of_x_axis, $s_val_of_y, $ending_val_of_x, $e_val_of_y)
1528
$graph->SetPlotBgColor( "red");
1529
$graph->SetPlotBorderType( "left");
1530
$graph->SetBackgroundColor( "orange"); // set the chart background
1532
//you can set the x title by one line or as commented three lines
1533
$graph->SetXTitle("SD X title", "both"); // para = ($title, $position); $postion= plotup or plotdown or both or none
1534
$graph->SetYTitle('SD Y title',"both"); // plotright or plotleft or both or both
1537
/*$graph->SetXLabel( "Year");
1538
$graph->SetHorizTickIncrement( "5");
1539
$graph->SetXGridLabelType( "title");*/
1542
$graph->SetVertTickIncrement( "500"); //the gap between two values in the Y axis
1543
$graph->SetPrecisionY( "0"); // determine how many decimal points should be there in Y axis values
1544
$graph->SetYGridLabelType( "data");
1545
$graph->SetLightGridColor( "blue");
1546
$graph->SetOutputFile("barChart.png");
1549
//$graph->SetNewPlotAreaPixels(70,120,375,220);
1550
$graph->SetPlotAreaWorld(0,0,6,2000);
1551
$graph->DrawGraph();
1555
function _shn_ims_double_smoothing($catalog_id,$inv_id,$time_period)
1560
$sql1="SELECT * FROM ims_optimization WHERE catalog_id='$catalog_id' AND inv_id='$inv_id';";
1561
$ims1=$db->Execute($sql1);
1562
while(!$ims1==NULL && !$ims1->EOF)
1564
$week=$ims1->fields['week'];
1565
$forecasted_value=$ims1->fields['forecasted_value'];
1571
$double_forecasted_value=0;
1576
$double_forecasted_value=($beta*($forecasted_value-$temp)) + ((1-$beta)*$double_forecasted_value_temp);
1580
$sql2="UPDATE ims_optimization SET double_forecasted_value='{$double_forecasted_value}' WHERE catalog_id='$catalog_id' AND inv_id='$inv_id' AND week='$week';";
1581
$ims2=$db->Execute($sql2);
1585
$double_forecasted_value_temp=$double_forecasted_value;
1586
$temp=$forecasted_value;
1590
//return $double_forecasted_value_temp;
1593
function _shn_ims_double_smoothing_forecast($catalog_id,$inv_id,$week)
1600
$query1="SELECT * FROM ims_optimization WHERE catalog_id='$catalog_id' AND inv_id='$inv_id' AND week>='$week';";
1601
$ims_query1=$db->Execute($query1);
1603
while(!$ims_query1==NULL && !$ims_query1->EOF)
1605
$forecasted_value=$ims_query1->fields['forecasted_value'];
1606
$double_forecasted_value=$ims_query1->fields['double_forecasted_value'];
1607
$time=$ims_query1->fields['week'];
1612
$forecasted_temp=$forecasted_value;
1613
$double_forecasted_temp=$double_forecasted_value;
1620
$ims_query1->MoveNext();
1623
$double_forecast=($beta*($forecasted_value-$forecasted_temp)) + ((1-$beta)*$double_forecasted_temp);
1625
return $double_forecast;
1630
********************************************************************************
1631
******************************************** Expired Items Report ************** ********************************************************************************
1634
function _shn_ims_expired_item_report()
1641
$table_data = array();
1644
$sql="SELECT item_id,inv_id,suplier_id,item_name,amount,unit,manufactured_date,expire_date FROM ims_item_records WHERE state='$state';";
1645
//$ims = $db->Execute($sql1);
1646
$ims = $db->Execute($sql);
1648
$suplier_array=array();
1650
while (!$ims==NULL && !$ims->EOF)
1652
$table_row = "row".$row_coount++;
1653
$table_row = array();
1655
$item_id=$ims->fields["item_id"];
1656
$inv_id=$ims->fields["inv_id"];
1657
$suplier_id=$ims->fields["suplier_id"];
1659
$suplier_array=_shn_or_get_suplier_name($suplier_id);
1660
$suplier_name=$suplier_array[$suplier_id];
1662
//$category=$ims->fields["category"];
1664
$table_row ["name"]= $ims->fields["item_name"];
1665
$table_row ["amount"]= $ims->fields["amount"];
1666
$unit=$ims->fields["unit"];
1667
$unit_name=get_unit_name($unit);
1668
$table_row ["unit"]= $unit_name;
1669
$table_row ["manu_date"]= $ims->fields["manufactured_date"];
1670
$table_row ["exp_date"]= $ims->fields["expire_date"];
1672
$sql3="SELECT inventory_name FROM ims_inventory_records WHERE inv_uuid='$inv_id';";
1673
$ims3=$db->Execute($sql3);
1675
$table_row ["inventory"]= $ims3->fields['inventory_name'];
1676
//$ims3->fields['suplier']=$suplier_name;
1677
//echo $suplier_name;
1679
$table_row ["suplier"]=$suplier_name;
1681
array_push($table_data,$table_row);
1691
*************************************** Destryed Item Report ********************************************************************************
1694
function _shn_ims_destroyed_item_report()
1701
$table_data = array();
1704
$sql1="SELECT inv_id,suplier_id,item_name,amount,unit,manufactured_date,expire_date FROM ims_item_records WHERE state='$state';";
1705
$ims1=$db->Execute($sql1);
1707
$suplier_array=array();
1709
while (!$ims1==NULL && !$ims1->EOF)
1711
$table_row = "row".$row_coount++;
1712
$table_row = array();
1714
$inv_id=$ims1->fields['inv_id'];
1715
$suplier_id=$ims1->fields['suplier_id'];
1716
$suplier_array=_shn_or_get_suplier_name($suplier_id);
1717
$suplier_name=$suplier_array[$suplier_id];
1718
$item_name=$ims1->fields['item_name'];
1719
$amount=$ims1->fields['amount'];
1720
$unit=$ims1->fields['unit'];
1721
$unit_name=get_unit_name($unit);
1722
$manufactured_date=$ims1->fields['manufactured_date'];
1723
$expire_date=$ims1->fields['expire_date'];
1725
$sql2="SELECT inventory_name FROM ims_inventory_records WHERE inv_uuid='$inv_id';";
1726
$ims2=$db->Execute($sql2);
1728
$inventory_name=$ims2->fields['inventory_name'];
1730
$table_row['name']=$item_name;
1731
$table_row['amount']=$amount;
1732
$table_row['unit']=$unit_name;
1733
$table_row['manu_date']=$manufactured_date;
1734
$table_row['exp_date']=$expire_date;
1735
$table_row['inventory']=$inventory_name;
1736
$table_row['suplier']=$suplier_name;
1738
array_push($table_data,$table_row);
1747
************************************************ Re-Order Level Report ********************************************************************
1750
function _shn_ims_reorder_level_report()
1755
$table_data = array();
1758
$sql1="SELECT catalog_id,inv_id,minimum_quantity,unit FROM ims_reorder_level;";
1759
$ims1=$db->Execute($sql1);
1761
$state = "destroyed";
1766
while (!$ims1==NULL && !$ims1->EOF)
1768
$table_row = "row".$row_coount++;
1769
$table_row = array();
1771
$catalog_id_min=$ims1->fields['catalog_id'];
1773
$inv_id_min=$ims1->fields['inv_id'];
1775
$minimum_quantity=$ims1->fields['minimum_quantity'];
1778
$unit=$ims1->fields['unit'];
1780
$unit_name=get_unit_name($unit);
1782
$sql2 = "SELECT unit,amount FROM ims_item_records WHERE catalog_id='$catalog_id_min' AND inv_id='$inv_id_min'AND state!='$state';";
1783
$ims2 =$db->Execute($sql2);
1785
while(!$ims2==NULL && !$ims2->EOF)
1788
$current_unit=$ims2->fields['unit'];
1789
$current_amount=$ims2->fields['amount'];
1792
$multiplier=unit_converter($unit,$current_unit);
1795
$current_amount_convert=$current_amount*$multiplier;
1797
$sum_amount=$sum_amount+$current_amount_convert;
1805
if($sum_amount<$minimum_quantity)
1807
$total_amount=$sum_amount;
1809
$sql3 = "SELECT item_id,item_name,unit FROM ims_item_records WHERE catalog_id='$catalog_id_min' AND inv_id='$inv_id_min';";
1810
$ims3 = $db->Execute($sql3);
1815
$sql4 = "SELECT inventory_name FROM ims_inventory_records WHERE inv_uuid='$inv_id_min';";
1816
$ims4 = $db->Execute($sql4);
1817
$inventory_name=$ims4->fields['inventory_name'];
1820
$item_id=$ims3->fields["item_id"];
1826
$item_name=$ims3->fields["item_name"];
1828
$unit=$ims3->fields["unit"];
1831
$table_row['name']=$item_name;
1832
$table_row['amount']=$total_amount;
1833
$table_row['unit']=$unit_name;
1834
$table_row['inventory']=$inventory_name;
1838
else if($sum_amount>=$minimum_quantity)
1842
array_push($table_data,$table_row);
1849
function _shn_ims_validate_sub_cat_form()
1855
$max_depth = get_max_depth();
1856
for($i=0;$i<$max_depth;$i++)
1858
$itemid = trim($_POST[$i]);
1865
if($itemid==null || $itemid=='none')
1867
//add_error(_t(SHN_IMS_CATALOGUE_MISSING));
1874
function _shn_ims_location_string($loc)
1879
shn_get_parents($loc,&$loc_arr);
1880
if($loc_arr[0]=='unknown'){
1881
shn_form_label(_t("Organization Location"),"Unknown");
1884
$max=count($loc_arr)-1;
1885
array_pop($loc_arr);
1886
for($count=0;$count<$max;$count++){
1887
$x=array_pop($loc_arr);
1888
$q="SELECT name FROM location WHERE loc_uuid='{$x}'";
1889
$res=$db->Execute($q);
1891
$location=$location.$res->Fields("name");
1893
$location=$location." -->".$res->Fields("name");
1901
function _shn_ims_get_locid($range_end){
1902
// if($_SESSION['ims_5']!=null)
1903
// return $_SESSION['ims_5'];
1904
// else if($_SESSION['ims_4']!=null)
1905
// return $_SESSION['ims_4'];
1906
// else if($_SESSION['ims_3']!=null)
1907
// return $_SESSION['ims_3'];
1908
// else if($_SESSION['ims_2']!=null)
1909
// return $_SESSION['ims_2'];
1911
// return $_SESSION['ims_1'];
1913
for($range_end; $range_end>0; $range_end--) {
1914
$var='rms_'.$range_end;
1915
if($_SESSION[$var]!=null && $_SESSION[$var]!="0")
1916
return $_SESSION[$var];
1921
function _shn_ims_get_parent_locations($location_id)
1929
$locatiion_array=array();
1930
$location_array[0]=$location_id;
1932
$sql="SELECT * FROM location;";
1933
$ims=$db->Execute($sql);
1935
while(!$ims==NULL && !$ims->EOF)
1937
$parent_id=$ims->fields['parent_id'];
1938
$loc_uuid=$ims->fields['loc_uuid'];
1941
if($parent_id==$location_id)
1949
$location_array[$i]=$loc_uuid;
1957
return $location_array;
1960
function _shn_ims_get_shelter_name()
1964
$shelter_array=array();
1965
$sql="SELECT * FROM camp_general;";
1966
$ims=$db->Execute($sql);
1967
$shelter_array['']='';
1968
while(!$ims==NULL && !$ims->EOF)
1970
$shelter_array[$ims->fields['c_uuid']]=$ims->fields['name'];
1973
return $shelter_array;
1976
function _shn_ims_get_organization_name()
1981
$sql="SELECT * FROM org_main;";
1982
$ims=$db->Execute($sql);
1984
while(!$ims==NULL && !$ims->EOF)
1986
$org_array[$ims->fields['o_uuid']]=$ims->fields['name'];
1992
function _shn_ims_get_victim()
1996
$victim_array=array();
1997
$sql="SELECT pg.g_uuid as g_uuid,pu.p_uuid as p_uuid,pg.opt_group_type as group_name,pu.full_name as full_name,pu.family_name as family_name,pu.l10n_name as l10n_name,pu.custom_name as custom_name FROM pgroup pg,person_to_pgroup ptg,person_uuid pu WHERE pg.g_uuid=ptg.g_uuid and ptg.p_uuid=pu.p_uuid;";
1998
$ims=$db->Execute($sql);
2000
$victim_array['']='';
2001
while(!$ims==NULL && !$ims->EOF)
2004
$victim_array[$ims->fields['g_uuid']]=$ims->fields['full_name']." ".$ims->fields['family_name'];
2007
return $victim_array;