forked from Tabuley/HLH
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_tz_insurance.php
More file actions
executable file
·2209 lines (1886 loc) · 79.2 KB
/
class_tz_insurance.php
File metadata and controls
executable file
·2209 lines (1886 loc) · 79.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
require_once($root_path.'include/care_api_classes/class_core.php');
/**
* Insurance methods for tanzania (the product-module is completely rewritten by Alexander Irro)
*
* Note this class should be instantiated only after a "$db" adodb connector object has been established by an adodb instance
* @author Alexander Irro (Version 1.0.0) - alexander.irro@merotech.de
* @copyright 2006 Robert Meggle (MEROTECH info@merotech.de)
* @package care_api from Elpidio Latirilla
*/
class Insurance_tz extends Core {
var $tbl_company='care_tz_company';
var $tbl_temp="tmp_search_results";
var $fields_tbl_company=array(
'id',
'name',
'contact',
'email',
'phone_code',
'phone_nr',
'po_box',
'city',
'start_date',
'end_date');
var $result;
var $rs_fuzziness;
var $pid;
// Constructor
function Insurance_tz() {
return TRUE;
}
//------------------------------------------------------------------------------
// Methods:
function CheckForValidContract($PID,$timestamp=0,$company_id=0) {
/*
* Retruns -2 when this person is contracted to another company!
*/
global $db;
$debug=FALSE;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
if($timestamp==0) $timestamp = time();
if ($debug) {
echo "check for $PID for Company-ID $company_id <br>";
echo "Is there a company for $PID: ".$this->GetCompanyFromPID($PID)."<br>";
}
//$db_company is the (possible) company for this PID what comes out of database. Could be empty or the Id of the company.
$db_company=$this->GetCompanyFromPID($PID);
if (empty($company_id)) {
$company_id = $db_company;
} else {
// Check if the company_id (as parameter) is the same like what we have in the database:
if ( ($company_id <> $db_company) && (!empty($db_company))) {
return -2;
}
}
if ($debug) echo "CheckForValidContract::GetCompanyFromPID returns: ".$company_id."<br>";
$contractarray = $this->GetActualContractForCompanyAsArray($company_id);
//echo $contractarray['start_date']."<".$timestamp." && ".$contractarray['end_date'].">".$timestamp;
if($contractarray['start_date']<$timestamp && $contractarray['end_date']>$timestamp)
{
$this->sql="SELECT i.*, it.ceiling FROM care_tz_insurance i, care_tz_insurance_types it WHERE company_id=".$company_id." AND PID=".$PID." AND parent= ".$contractarray['id']." AND cancel_flag=0 AND it.id = i.plan ORDER BY i.id DESC LIMIT 1";
$this->result = $db->Execute($this->sql);
if ($debug) echo $this->sql;
if($this->result)
if($this->row = $this->result->FetchRow())
{
$this->row['is_valid']=TRUE;
$this->row['contract_start_date'] = $contractarray['start_date'];
$this->row['contract_end_date'] = $contractarray['end_date'];
return $this->row;
}
}
return false;
}
// -----------------------------------------------------------------------------
function GetCompanyIDFromContract($contract) {
global $db;
$debug=FALSE;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
$this->sql="SELECT company_id FROM care_tz_insurance WHERE id=".$contract;
$this->result = $db->Execute($this->sql);
if($this->row = $this->result->FetchRow())
{
return $this->row['company_id'];
}
return false;
}
// -----------------------------------------------------------------------------
function GetCompanyFromPID($PID) {
global $db;
if (!$PID) return FALSE;
$debug=FALSE;
$company_id=FALSE;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
$this->sql="SELECT company_id FROM care_tz_insurance WHERE PID=$PID ORDER BY id DESC LIMIT 1";
$this->result = $db->Execute($this->sql);
if($this->row = $this->result->FetchRow()) {
$company_id=$this->row['company_id'];
}
return $company_id;
}
// -----------------------------------------------------------------------------
function GetCompanyFromParent($parent,$start)
{
global $db;
$debug=FALSE;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
//Abort reason
if(!$parent) return false;
if($start)
$where = 'WHERE PID='.$parent;
else
$where = 'WHERE id='.$parent;
$this->sql="SELECT company_id, parent FROM care_tz_insurance $where ORDER BY id DESC LIMIT 1";
$this->result = $db->Execute($this->sql);
if($this->row = $this->result->FetchRow())
{
if($this->row['parent']!=-1)
{
//Recursive call of next parent
return $this->GetCompanyFromParent($this->row['parent'],false);
}
else
{
//We finally got it, return it now all the way back
return $this->row['company_id'];
}
}
}
function GetAllInsurancesAsArray($JUST_CONTRACTED=FALSE,$hide_flag) {
/**
* If you want just a list of contracted companies, give this function a TRUE as parameter
*/
global $db;
$debug=FALSE;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
if($hide_flag)
{
$hide_sql1 = " WHERE hide_company_flag=0";
$hide_sql2 = " AND care_tz_company.hide_company_flag=0";
}
else
{
$hide_sql1=false;
$hide_sql2=false;
}
if (!$JUST_CONTRACTED)
$this->sql="SELECT id, name, contact, email, phone_code, phone_nr, po_box, city, start_date, end_date, hide_company_flag FROM care_tz_company ".$hide_sql1." ORDER BY id ASC";
else {
// This gives a list of companies what are somehow dedicated to a list of contracted companies
// No check if the contract is valid to any time period...
$this->sql="SELECT
care_tz_company.id,
care_tz_company.name,
care_tz_company.contact,
care_tz_company.email,
care_tz_company.phone_code,
care_tz_company.phone_nr,
care_tz_company.po_box,
care_tz_company.city,
care_tz_company.start_date,
care_tz_company.end_date,
care_tz_company.invoice_flag,
care_tz_company.credit_preselection_flag,
care_tz_company.hide_company_flag
FROM care_tz_company
INNER JOIN care_tz_insurance ON care_tz_insurance.company_id=care_tz_company.id
INNER JOIN care_tz_insurance_types ON care_tz_insurance_types.id=care_tz_insurance.plan
WHERE parent=-1".$hide_sql2."
ORDER BY care_tz_company.name";
}
$this->result = $db->Execute($this->sql);
$counter=0;
while($this->row = $this->result->FetchRow())
{
$return[$counter++] = $this->row;
}
return $return;
}
// -----------------------------------------------------------------------------
function GetContractsForCompanyAsArray($company_id) {
global $db;
$debug=FALSE;
$return=FALSE;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
/*
if ($this->is_company_just_invoiced($company_id)) {
# This company does not have a ceiling, does not have any entry what allocates to care_tz_insurance_types.
# so there is no need to join this table.
$this->sql="SELECT i.id, start_date, end_date, cancel_flag, paid_flag FROM care_tz_insurance i WHERE PID=0 AND company_id=$company_id";
} else {
$this->sql="SELECT i.id, it.name, plan, start_date, end_date, cancel_flag, paid_flag FROM care_tz_insurance i, care_tz_insurance_types it WHERE PID=0 AND company_id=$company_id AND it.id = i.plan ORDER BY end_date DESC";
}
*/
$this->sql="SELECT i.id, start_date, end_date, cancel_flag, paid_flag FROM care_tz_insurance i WHERE PID=0 AND company_id=$company_id";
if ($debug) echo $this->sql;
$this->result = $db->Execute($this->sql);
$counter=0;
if ($this->result)
while($this->row = $this->result->FetchRow()) {
$return[$counter++] = $this->row;
}
return $return;
}
// -----------------------------------------------------------------------------
function GetContractMemberFromTimestamp($PID, $time) {
global $db, $bill_obj;
$debug=false;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
// Select matching contract
$sql="SELECT id, company_id, start_date, end_date, timestamp, cancel_flag, paid_flag
FROM care_tz_insurance i
WHERE start_date <".$time."
AND end_date >=".$time."
AND id
IN (
SELECT parent AS id
FROM care_tz_insurance i
WHERE PID = ".$PID."
)";
if($result = $db->Execute($sql))
{
if($row = $result->FetchRow())
{
$matchingContract = $row;
}
$sql="SELECT i.id, company_id, it.ceiling, i.ceiling_startup_subtraction, it.name, plan, timestamp, cancel_flag, paid_flag, gets_company_credit
FROM care_tz_insurance i, care_tz_insurance_types it
WHERE it.id = i.plan AND parent = ".$matchingContract['id']." AND PID=".$PID;
if($result = $db->Execute($sql))
if($row = $result->FetchRow())
{
$matchingContract['Member'] = $row;
}
}
return $matchingContract;
}
// -----------------------------------------------------------------------------
function GetActualContractForCompanyAsArray($company_id) {
global $db;
$debug=FALSE;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
if(!$company_id) return false;
if ($this->is_company_just_invoiced($company_id)) {
# This company does not have a ceiling, does not have any entry what allocates to care_tz_insurance_types.
# so there is no need to join this table.
$this->sql="SELECT i.id, start_date, end_date, cancel_flag, paid_flag FROM care_tz_insurance i WHERE parent=-1 AND company_id=$company_id AND start_date<".time()." AND end_date > ".time()." AND cancel_flag=0 ORDER BY id DESC";
} else {
$this->sql="SELECT i.id, it.name, plan, start_date, end_date, cancel_flag, paid_flag FROM care_tz_insurance i, care_tz_insurance_types it WHERE parent=-1 AND company_id=$company_idAND it.id = i.plan AND start_date<".time()." AND end_date > ".time()." AND cancel_flag=0 ORDER BY id DESC";
}
$this->result = $db->Execute($this->sql);
$counter=0;
if($this->row = $this->result->FetchRow())
{
return $this->row;
}
return false;
}
function GetContractForCompanyAsArray($company_id) {
global $db;
$debug=false;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
if(!$company_id) return false;
$this->sql="SELECT i.id, it.name, plan, start_date, end_date, cancel_flag, paid_flag, gets_company_credit FROM care_tz_insurance i, care_tz_insurance_types it WHERE parent=-1 AND company_id=$company_id
AND it.id = i.plan AND start_date>".time()." AND cancel_flag=0 ORDER BY id DESC LIMIT 0,1";
$this->result = $db->Execute($this->sql);
$counter=0;
if($this->row = $this->result->FetchRow())
{
return $this->row;
}
return false;
}
// -----------------------------------------------------------------------------
function GetContractsByIDAsArray($contract_id) {
global $db;
$debug=false;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
$this->sql="SELECT i.id, i.company_id, it.name, plan, start_date, end_date, cancel_flag FROM care_tz_insurance i, care_tz_insurance_types it WHERE i.id = ".$contract_id." AND it.id = i.plan ORDER BY end_date DESC";
$this->result = $db->Execute($this->sql);
if($this->row = $this->result->FetchRow())
{
return $this->row;
}
return false;
}
// -----------------------------------------------------------------------------
function GetInsuranceTypesAsArray() {
global $db;
$debug=false;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
$this->sql="SELECT id, name, ceiling, is_disabled FROM care_tz_insurance_types ORDER BY id ASC";
$this->result = $db->Execute($this->sql);
$counter=0;
while($this->row = $this->result->FetchRow())
{
$return[$counter++] = $this->row;
}
return $return;
}
// -----------------------------------------------------------------------------
function GetInsuranceTypeAsArray($id) {
global $db;
$debug=FALSE;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
$this->sql="SELECT id, name, ceiling, is_disabled FROM care_tz_insurance_types WHERE id=".$id;
$this->result = $db->Execute($this->sql);
if($this->row = $this->result->FetchRow())
{
return $this->row;
}
return false;
}
// -----------------------------------------------------------------------------
function GetInsuranceAsArray($id){
global $db;
if(!$id || !is_numeric($id)) return false;
$this->debug=FALSE;
($this->debug) ? $db->debug=TRUE : $db->debug=FALSE;
if ($this->is_company_just_invoiced($id)) {
# This company does not have a ceiling, does not have any entry what allocates to care_tz_insurance_types.
# so there is no need to join this table.
$this->sql="SELECT
care_tz_company.id,
care_tz_company.name,
care_tz_company.contact,
care_tz_company.email,
care_tz_company.phone_code,
care_tz_company.phone_nr,
care_tz_company.po_box,
care_tz_company.city,
care_tz_company.start_date,
care_tz_company.end_date,
care_tz_company.invoice_flag,
care_tz_company.credit_preselection_flag,
care_tz_company.hide_company_flag,
care_tz_company.prepaid_amount,
care_tz_insurance.plan as insurance
FROM care_tz_company
LEFT JOIN care_tz_insurance ON care_tz_insurance.company_id=care_tz_company.id
WHERE care_tz_company.id=$id";
} else {
$this->sql="SELECT
care_tz_company.id,
care_tz_company.name,
care_tz_company.contact,
care_tz_company.email,
care_tz_company.phone_code,
care_tz_company.phone_nr,
care_tz_company.po_box,
care_tz_company.city,
care_tz_company.start_date,
care_tz_company.end_date,
care_tz_company.invoice_flag,
care_tz_company.credit_preselection_flag,
care_tz_company.hide_company_flag,
care_tz_company.prepaid_amount,
care_tz_insurance_types.name as InsuranceName,
care_tz_insurance.plan as insurance
FROM care_tz_company
LEFT JOIN care_tz_insurance ON care_tz_insurance.company_id=care_tz_company.id
LEFT JOIN care_tz_insurance_types ON care_tz_insurance_types.id=care_tz_insurance.plan
WHERE care_tz_company.id=$id";
}
if ($this->debug) echo $this->sql;
if ( $this->result = $db->Execute($this->sql))
if($this->row = $this->result->FetchRow()) {
return $this->row;
}
// anyway, when the script is comming to this line, there is something wrong
// and we have to say that there was an error...
return false;
}
// -----------------------------------------------------------------------------
function GetPlanForPID($pid) {
/*
* Getting the correspodending plan for a specific PID. If there is no plan, it will return FALSE
*/
global $db;
if(!$pid) return false;
$debug=FALSE;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
$this->sql="SELECT plan FROM care_tz_insurance where PID=$pid limit 0,1";
$this->result = $db->Execute($this->sql);
if($this->result)
{
if($this->row = $this->result->FetchRow())
{
return $this->row['plan'];
}
}
return FALSE;
}
// -----------------------------------------------------------------------------
function GetInsuranceIDByCompanyID($id){
global $db;
if(!$id || !is_numeric($id)) return false;
$debug=FALSE;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
$this->sql="SELECT id FROM care_tz_insurance WHERE company_id =$id AND parent=-1 ORDER BY company_parent DESC LIMIT 1";
$this->result = $db->Execute($this->sql);
if($this->result)
{
if($this->row = $this->result->FetchRow())
{
return $this->row;
}
}
return 0;
}
//------------------------------------------------------------------------------
function CreateInsuranceRoot($id){
global $db;
$debug=FALSE;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
$company = $this->GetInsuranceAsArray($id);
$this->sql="INSERT INTO care_tz_insurance SET
parent=-1,
company_id='".$id."',
PID=0,
company_parent=0,
ceiling_startup_subtraction=0,
plan=0,
start_date=".mktime(0,0,0,date("Y"),1,1).",
end_date=".mktime(23,59,59,date("Y"),12,31).",
timestamp='".time()."',
cancel_flag=0";
$this->result = $db->Execute($this->sql);
return $this->GetInsuranceIDByCompanyID($id);
}
//------------------------------------------------------------------------------
function CreateInsuranceContract($company_id, $plan, $start, $end){
global $db;
$debug=TRUE;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
$company_parent = $this->GetInsuranceIDByCompanyID($company_id);
if (empty($plan))
$plan=-1;
$this->sql="INSERT INTO care_tz_insurance SET
parent=-1,
company_id='".$company_id."',
PID=0,
company_parent='".$company_parent."',
ceiling_startup_subtraction=0,
plan=".$plan.",
start_date=".$start.",
end_date=".$end.",
timestamp='".time()."',
cancel_flag=0";
$this->result = $db->Execute($this->sql);
$newId= $this->GetInsuranceIDByCompanyID($id);
$this->RenewContractMembers($newId, $company_parent, $company_id);
return $newId;
}
//------------------------------------------------------------------------------
function RenewContractMembers($new_id, $old_id, $company_id){
global $db;
$debug=FALSE;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
$this->sql="INSERT INTO care_tz_insurance (parent, company_id, PID, company_parent, ceiling_startup_substraction,
plan, start_date, end_date, timestamp, cancel_flag, paid_flag)
SELECT ".$new_id.", company_id, PID, 0, 0, plan, 0, 0, ".time().", 0, 0 WHERE cancel_flag=0 AND parent = ".$old_id;
$this->result = $db->Execute($this->sql);
return true;
}
//------------------------------------------------------------------------------
function GetInsuranceContractsAsArray($id,$timestamp,$guilty=0){
/*
Definitions:
$guilty < 0 : Show all expired contracts
$guilty = 0 : Show actual contract
$guilty > 0 : Show future contracs
*/
global $db;
if(!$id || !is_numeric($id)) return false;
if(!$timestamp) $timestamp=time();
$debug=FALSE;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
if($guilty<0)
{
$where = ' AND end_date < '.$timestamp;
}
elseif($guilty==0)
{
$where = ' AND start_date < '.$timestamp.' AND end_date > '.$timestamp;
}
else
{
$where = ' AND start_date > '.$timestamp;
}
$this->sql="SELECT * FROM care_tz_insurance WHERE company_id=$id"; //.$where;
$this->result = $db->Execute($this->sql);
$counter=0;
while($this->row = $this->result->FetchRow())
{
if($this->row['PID']>0)
{
$return[$this->row['PID']]=$this->row;
}
}
return $return;
}
//------------------------------------------------------------------------------
function GetMembersOfContractID($id){
global $db;
$this->debug=FALSE;
($this->debug) ? $db->debug=TRUE : $db->debug=FALSE;
if ($this->debug) echo "calling GetMembersOfContractID($id)<br>";
if(!$id || !is_numeric($id)) {
if ($this->debug) echo "NO PID OR PID IS NOT NUMMERIC<br>";
return false;
}
$this->sql="SELECT * FROM care_tz_insurance WHERE PID>0 and parent=$id";
if ($this->debug) echo $this->sql;
$this->result = $db->Execute($this->sql);
while($this->row = $this->result->FetchRow())
{
$return[$this->row['PID']]=$this->row;
}
return $return;
}
//------------------------------------------------------------------------------
function InsertNewInsuranceCompany($dataarray){
global $db;
if(!$dataarray) return false;
$debug=false;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
if($dataarray['invoice_flag']) $invoice=1; else $invoice=0;
if($dataarray['credit_preselection_flag']) $credit=1; else $credit=0;
$this->sql="INSERT INTO care_tz_company SET
name='".$dataarray['name']."',
contact='".$dataarray['contact']."',
email='".$dataarray['email']."',
phone_code='".$dataarray['phone_code']."',
phone_nr='".$dataarray['phone_nr']."',
po_box='".$dataarray['po_box']."',
city='".$dataarray['city']."',
invoice_flag='".$invoice."',
credit_preselection_flag='".$credit."'";
$this->result = $db->Execute($this->sql);
return $db->Insert_ID();;
}
//------------------------------------------------------------------------------
function UpdateInsuranceCompany($dataarray){
global $db;
$debug=FALSE;
if(!$dataarray) return false;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
if($dataarray['invoice_flag']) $invoice=1; else $invoice=0;
if($dataarray['credit_preselection_flag']) $credit=1; else $credit=0;
if($dataarray['hide_company_flag']) $hide=1; else $hide=0;
$this->sql="UPDATE care_tz_company SET
name='".$dataarray['name']."',
contact='".$dataarray['contact']."',
email='".$dataarray['email']."',
phone_code='".$dataarray['phone_code']."',
phone_nr='".$dataarray['phone_nr']."',
po_box='".$dataarray['po_box']."',
city='".$dataarray['city']."',
invoice_flag='".$invoice."',
credit_preselection_flag='".$credit."',
hide_company_flag='".$hide."',
prepaid_amount='".$dataarray['prepaid_amount']."'
WHERE id=".$dataarray['id'];
$this->result = $db->Execute($this->sql);
$this->sql="UPDATE care_tz_insurance SET
plan='".$dataarray['insurance']."'
WHERE company_id=".$dataarray['id'];
$this->result = $db->Execute($this->sql);
return true;
}
//------------------------------------------------------------------------------
function UpdateInsuranceType($dataarray){
global $db;
if(!$dataarray) return false;
$debug=false;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
if(!$dataarray['is_disabled']) $dataarray['is_disabled'] = 0;
$this->sql="UPDATE care_tz_insurance_types SET
name='".$dataarray['name']."',
ceiling='".$dataarray['ceiling']."',
is_disabled='".$dataarray['is_disabled']."'
WHERE id=".$dataarray['id'];
$this->result = $db->Execute($this->sql);
return true;
}
//------------------------------------------------------------------------------
function InsertInsuranceType($dataarray){
global $db;
if(!$dataarray) return false;
$debug=false;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
if(!$dataarray['is_disabled']) $dataarray['is_disabled'] = 0;
$this->sql="INSERT INTO care_tz_insurance_types SET
name='".$dataarray['name']."',
ceiling='".$dataarray['ceiling']."',
is_disabled='".$dataarray['is_disabled']."'";
$this->result = $db->Execute($this->sql);
return true;
}
//------------------------------------------------------------------------------
function ConcludeContractForPID($pid, $parent, $company_id, $startup_subtraction, $plan, $companycredit){
global $db;
$debug=FALSE;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
// Check up if this person is somehow in that database...
$this->sql = "SELECT * FROM care_tz_insurance WHERE PID=$pid AND parent=$parent";
$this->result = $db->Execute($this->sql);
if($companycredit) $companycredit=1; else $companycredit=0;
if ($this->result->RecordCount()>0) {
if ($debug) $this->GetCompanyFromPID($pid);
$this->sql="UPDATE care_tz_insurance SET
parent='".$parent."',
company_id='".$company_id."',
company_parent=0,
ceiling_startup_subtraction='".$startup_subtraction."',
gets_company_credit='".$companycredit."',
plan='".$plan."',
start_date='0',
end_date='0',
timestamp='".time()."',
cancel_flag=0 WHERE PID='".$pid."' AND parent='".$parent."'";
} else {
$this->sql="INSERT INTO care_tz_insurance SET
parent='".$parent."',
company_id='".$company_id."',
company_parent=0,
PID='".$pid."',
ceiling_startup_subtraction='".$startup_subtraction."',
gets_company_credit='".$companycredit."',
plan='".$plan."',
start_date='0',
end_date='0',
timestamp='".time()."',
cancel_flag=0";
}
$this->result = $db->Execute($this->sql);
return true;
}
//------------------------------------------------------------------------------
function UpdateContractsArray($dataarray){
global $db;
if(!$dataarray) return false;
$debug=FALSE;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
$temparray = $dataarray;
//if($debug) var_dump($dataarray);
while(list($x,$v) = each($dataarray))
{
//if($debug) echo '<br>('.$x.') ';
if(strstr($x,"this_"))
{
$currentpid = substr(strstr($x,"this_"),5);
if($temparray['this_'.$currentpid]=="conclude" && $temparray['action_'.$currentpid]=="conclude")
{ if ($debug) echo "conclude";
$parent = $this->GetInsuranceIDByCompanyID($temparray['insurance']);
$this->ConcludeContractForPID($currentpid, $parent['id'], $temparray['insurance'], $temparray['startup_'.$currentpid], $temparray['plan_'.$currentpid], $temparray['credit_preselection_flag_'.$currentpid]);
}
elseif($temparray['this_'.$currentpid]=="cancel" && $temparray['action_'.$currentpid]=="cancel")
{ if ($debug) echo "cancel";
if($this->CancelContractForPID($temparray['contract_'.$currentpid]))
$status['cancel']++;
$this->SetContractPlanForPID($temparray['contract_'.$currentpid],$temparray['plan_'.$currentpid]);
if($temparray['startup_'.$currentpid] && is_numeric($temparray['startup_'.$currentpid]))
$this->SetContractStartupsubstractionForPID($temparray['contract_'.$currentpid],$temparray['startup_'.$currentpid]);
}
elseif($temparray['this_'.$currentpid]=="cancel" && !$temparray['action_'.$currentpid])
{ if ($debug) echo "weiss net";
if($this->EnableContractForPID($temparray['contract_'.$currentpid]))
$status['enable']++;
//$this->SetContractPlanForPID($temparray['contract_'.$currentpid],$temparray['plan_'.$currentpid]);
if($temparray['startup_'.$currentpid] && is_numeric($temparray['startup_'.$currentpid]))
$this->SetContractStartupsubstractionForPID($temparray['contract_'.$currentpid],$temparray['startup_'.$currentpid]);
}
}
//if($debug) echo $currentpid.' - ';
}
if($debug) echo $status['cancel'].' ---- '.$status['enable'];
return true;
}
//------------------------------------------------------------------------------
function CancelContractForPID($id){
global $db;
if(!$id) return false;
$debug=FALSE;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
$this->sql="UPDATE care_tz_insurance SET
cancel_flag=1
WHERE id=".$id;
$this->result = $db->Execute($this->sql);
return true;
}
//------------------------------------------------------------------------------
function EnableContractForPID($id){
global $db;
if(!$id) return TRUE;
$debug=FALSE;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
$this->sql="UPDATE care_tz_insurance SET
cancel_flag=0
WHERE id=".$id;
$this->result = $db->Execute($this->sql);
return true;
}
//------------------------------------------------------------------------------
function EnablePaymentForContract($id){
global $db;
if(!$id) return false;
$debug=false;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
$this->sql="UPDATE care_tz_insurance SET
paid_flag=1
WHERE id=".$id;
$this->result = $db->Execute($this->sql);
return true;
}
//------------------------------------------------------------------------------
function CancelPaymentForContract($id){
global $db;
if(!$id) return false;
$debug=false;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
$this->sql="UPDATE care_tz_insurance SET
paid_flag=0
WHERE id=".$id;
$this->result = $db->Execute($this->sql);
return true;
}
//------------------------------------------------------------------------------
function SetContractPlanForPID($id,$value){
global $db;
if(!$id) return false;
$debug=FALSE;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
$this->sql="UPDATE care_tz_insurance SET
plan=".$value."
WHERE id=".$id;
$this->result = $db->Execute($this->sql);
return true;
}
//------------------------------------------------------------------------------
function SetContractStartupsubstractionForPID($id,$value){
global $db;
if(!$id) return false;
$debug=false;
($debug) ? $db->debug=TRUE : $db->debug=FALSE;
$this->sql="UPDATE care_tz_insurance SET
ceiling_startup_subtraction=".$value."
WHERE id=".$id;
$this->result = $db->Execute($this->sql);
return true;
}
//------------------------------------------------------------------------------
function ShowListOfContractedMembers($company_id) {
global $db;
global $person_obj;
$this->debug=FALSE;
($this->debug) ? $db->debug=TRUE : $db->debug=FALSE;
if (!$company_id) return FALSE;
$this->sql="SELECT PID FROM care_tz_insurance WHERE PID>0 and cancel_flag=0 and company_id=$company_id";
if ($this->result = $db->Execute($this->sql)) {
if ($this->debug) echo "We have hits!";
while($this->row = $this->result->FetchRow()) {
if ($this->debug) echo $this->row['PID']." ";
$result=$person_obj->getAllInfoObject($this->row['PID']);
if($person = $result->FetchRow()) {
echo "<option value=\"".$this->row['PID']."\">".$person['selian_pid']." - ".$person['name_last'].", ".$person['name_first']." (".$person['date_birth'].")</option>\n";
}
}
} // end of while
return FALSE;
}
//------------------------------------------------------------------------------
function ShowInsuranceList($mode,$SHOWALL) {
global $LDID,$LDCompanyName,$LDCompanyName,$LDOptions;
/**
* Returns TRUE if this item number still exists in the database
*/
$bg="";
$ADDITIONALLY_INFO="";
$SHOWIT=FALSE;
$this->insurance_array = $this->GetAllInsurancesAsArray(FALSE, FALSE);
//[hide_company_flag]
echo '<table border="0" cellpadding="2" cellspacing="0">
<tr bgcolor=#ffff66>
<td align="center" width="30">'.$LDID.'</td>
<td align="center" width="240">'.$LDCompanyName.'</td>
<td colspan="2" align="center" width="50">'.$LDOptions.'</td>
</tr>
';
while(list($x,$v) = each($this->insurance_array)) {
// Do we have to show also the hidden companies?
if ($SHOWALL==1) {
$SHOWIT = TRUE;
} else if ( ($SHOWALL==0 && $v['hide_company_flag']==1) ) {
$SHOWIT = FALSE;
} else {
$SHOWIT = TRUE;
}
//echo $v['name'].":Show all is set to: $SHOWALL and hide_company_flag is set to ".$v['hide_company_flag']."-> SHOWIT is set to $SHOWIT<br>";
if ( $SHOWIT ) {
if ($v['hide_company_flag']) {
$ADDITIONALLY_INFO="<i>hidden</i>";
} else {
$ADDITIONALLY_INFO="";
}
if($bg=="#ffffaa")
$bg="#ffffdd";
else
$bg="#ffffaa";
echo '
<tr bgcolor='.$bg.'>
<td>'.$v['id'].'</td>
<td>'.$v['name'].'</td>';
if($mode=='report')
echo '
<td><div align="center"><a href="insurance_reports_company_contracts.php?id='.$v['id'].'"><img src="../../gui/img/common/default/documents.gif" alt="Show contracts" width="16" height="16" border="0"></a></td></tr>
</tr>';
else
echo '
<td><div align="center"><a href="insurance_company_tz_contracts.php?id='.$v['id'].'"><img src="../../gui/img/common/default/documents.gif" alt="Show contracts" width="16" height="16" border="0"></a>'.$ADDITIONALLY_INFO.'</td>
</tr>';
} // end of if
} // end of while
echo '</table>';
return true;
}
//------------------------------------------------------------------------------
function ShowMemberBillsOfContract($contract_id, $show_company_info) {
global $root_path, $person_obj;
global $LDContractID,$LDPlan,$LDTimeframe,$LDCompanyName,$LDCity,$LDContractPerson,$LDInsurancetype,
$LDPOBOX,$LDPOBOX,$LDPaybyInvoice,$LDYes,$LDNo,$LDPID,$LDplan,$LDCeiling,$LDPrepaidAmount,$LDName,
$LDTSH,$LDTotalSum;
/**
* Returns TRUE if this item number still exists in the database
*/
$this->contractmembers = $this->GetMembersOfContractID($contract_id);
$this->contract = $this->GetContractsByIDAsArray($contract_id);
$this->company = $this->GetInsuranceAsArray($this->GetCompanyIDFromContract($contract_id));
if($show_company_info) {
echo '
<table border="0" cellpadding="2" cellspacing="1">
<tr bgcolor="#FFBD72">
<td width="120">'.$LDContractID.' '.$this->contract['id'].'</td>
<td width="190">'.$LDPlan.' '.$this->contract['name'].'</td>
<td width="118">'.$LDTimeframe.'</td>
<td width="90" align="center">'.date("d.m.y", $this->contract['start_date']).'</td>
<td width="10">-</td>
<td width="80" align="center">'.date("d.m.y", $this->contract['end_date']).'</td>
</tr>
</table>
<table border="0" cellpadding="2" cellspacing="1">
<tr bgcolor=ffffaa>
<td width="120">'.$LDCompanyName.'</td>
<td width="190">'.$this->company['name'].'</td>
<td width="118">'.$LDCity.'</td>