Code Duplication    Length = 102-104 lines in 2 locations

src/Intraface/modules/invoice/ReminderGateway.php 1 location

@@ 53-156 (lines=104) @@
50
        return true;
51
    }
52
53
    function findAll()
54
    {
55
        $this->getDBQuery();
56
57
        $this->dbquery->setSorting("number DESC, this_date DESC");
58
        $i = 0;
59
60
        if ($this->dbquery->checkFilter("contact_id")) {
61
            $this->dbquery->setCondition("contact_id = ".intval($this->dbquery->getFilter("contact_id")));
62
        }
63
64
        if ($this->dbquery->checkFilter("invoice_id")) {
65
            $this->dbquery->setCondition("invoice_id = ".intval($this->dbquery->getFilter("invoice_id")));
66
        }
67
68
        if ($this->dbquery->checkFilter("text")) {
69
            $this->dbquery->setCondition("(description LIKE \"%".$this->dbquery->getFilter("text")."%\" OR girocode = \"".$this->dbquery->getFilter("text")."\" OR number = \"".$this->dbquery->getFilter("text")."\")");
70
        }
71
72
        if ($this->dbquery->checkFilter("from_date")) {
73
            $date = new Intraface_Date($this->dbquery->getFilter("from_date"));
74
            if ($date->convert2db()) {
75
                $this->dbquery->setCondition("this_date >= \"".$date->get()."\"");
76
            } else {
77
                $this->error->set("Fra dato er ikke gyldig");
78
            }
79
        }
80
81
        // Poster med fakturadato f�r slutdato.
82
        if ($this->dbquery->checkFilter("to_date")) {
83
            $date = new Intraface_Date($this->dbquery->getFilter("to_date"));
84
            if ($date->convert2db()) {
85
                $this->dbquery->setCondition("this_date <= \"".$date->get()."\"");
86
            } else {
87
                $this->error->set("Til dato er ikke gyldig");
88
            }
89
        }
90
91
        if ($this->dbquery->checkFilter("status")) {
92
            if ($this->dbquery->getFilter("status") == "-1") {
93
                // Beh�ves ikke, den tager alle.
94
                // $this->dbquery->setCondition("status >= 0");
95
            } elseif ($this->dbquery->getFilter("status") == "-2") {
96
                // Not executed = �bne
97
                if ($this->dbquery->checkFilter("to_date")) {
98
                    $date = new Intraface_Date($this->dbquery->getFilter("to_date"));
99
                    if ($date->convert2db()) {
100
                        // Poster der er executed eller cancelled efter dato, og sikring at executed stadig er det, da faktura kan s�ttes tilbage.
101
                        $this->dbquery->setCondition("(date_executed >= \"".$date->get()."\" AND status = 2) OR (date_cancelled >= \"".$date->get()."\") OR status < 2");
102
                    }
103
                } else {
104
                    // Hvis der ikke er nogen dato s� tager vi alle dem som p� nuv�rende tidspunkt har status under
105
                    $this->dbquery->setCondition("status < 2");
106
                }
107
            } else {
108
                switch ($this->dbquery->getFilter("status")) {
109
                    case "0":
110
                        $to_date_field = "date_created";
111
                        break;
112
113
                    case "1":
114
                        $to_date_field = "date_sent";
115
                        break;
116
117
                    case "2":
118
                        $to_date_field = "date_executed";
119
                        break;
120
121
                    case "3":
122
                        $to_date_field = "data_caneled";
123
                        break;
124
                }
125
126
                if ($this->dbquery->checkFilter("to_date")) {
127
                    $date = new Intraface_Date($this->dbquery->getFilter("to_date"));
128
                    if ($date->convert2db()) {
129
                        $this->dbquery->setCondition($to_date_field." <= \"".$date->get()."\"");
130
                    }
131
                } else {
132
                    // tager dem som p� nuv�rende tidspunkt har den angivet status
133
                    $this->dbquery->setCondition("status = ".intval($this->dbquery->getFilter("status")));
134
                }
135
            }
136
        }
137
138
        $this->dbquery->setSorting("number DESC");
139
        $db = $this->dbquery->getRecordset("id", "", false);
140
141
        $list = array();
142
        while ($db->nextRecord()) {
143
            $reminder = new Reminder($this->kernel, $db->f("id"));
144
            $list[$i] = $reminder->get();
145
            if (is_object($reminder->contact->address)) {
146
                $list[$i]['contact_id'] = $reminder->contact->get('id');
147
                $list[$i]['name'] = $reminder->contact->address->get('name');
148
                $list[$i]['address'] = $reminder->contact->address->get('address');
149
                $list[$i]['postalcode'] = $reminder->contact->address->get('postcode');
150
                $list[$i]['city'] = $reminder->contact->address->get('city');
151
            }
152
            $i++;
153
        }
154
        return $list;
155
    }
156
157
    function isFilledIn()
158
    {
159
        $db = new DB_Sql;

src/Intraface/modules/invoice/Reminder.php 1 location

@@ 366-467 (lines=102) @@
363
        return new DebtorAccount($this);
364
    }
365
366
    function getList()
367
    {
368
        $this->dbquery->setSorting("number DESC, this_date DESC");
369
        $i = 0;
370
371
        if ($this->dbquery->checkFilter("contact_id")) {
372
            $this->dbquery->setCondition("contact_id = ".intval($this->dbquery->getFilter("contact_id")));
373
        }
374
375
        if ($this->dbquery->checkFilter("invoice_id")) {
376
            $this->dbquery->setCondition("invoice_id = ".intval($this->dbquery->getFilter("invoice_id")));
377
        }
378
379
        if ($this->dbquery->checkFilter("text")) {
380
            $this->dbquery->setCondition("(description LIKE \"%".$this->dbquery->getFilter("text")."%\" OR girocode = \"".$this->dbquery->getFilter("text")."\" OR number = \"".$this->dbquery->getFilter("text")."\")");
381
        }
382
383
        if ($this->dbquery->checkFilter("from_date")) {
384
            $date = new Intraface_Date($this->dbquery->getFilter("from_date"));
385
            if ($date->convert2db()) {
386
                $this->dbquery->setCondition("this_date >= \"".$date->get()."\"");
387
            } else {
388
                $this->error->set("Fra dato er ikke gyldig");
389
            }
390
        }
391
392
        // Poster med fakturadato før slutdato.
393
        if ($this->dbquery->checkFilter("to_date")) {
394
            $date = new Intraface_Date($this->dbquery->getFilter("to_date"));
395
            if ($date->convert2db()) {
396
                $this->dbquery->setCondition("this_date <= \"".$date->get()."\"");
397
            } else {
398
                $this->error->set("Til dato er ikke gyldig");
399
            }
400
        }
401
402
        if ($this->dbquery->checkFilter("status")) {
403
            if ($this->dbquery->getFilter("status") == "-1") {
404
                // Beh�ves ikke, den tager alle.
405
                // $this->dbquery->setCondition("status >= 0");
406
            } elseif ($this->dbquery->getFilter("status") == "-2") {
407
                // Not executed = åbne
408
                if ($this->dbquery->checkFilter("to_date")) {
409
                    $date = new Intraface_Date($this->dbquery->getFilter("to_date"));
410
                    if ($date->convert2db()) {
411
                        // Poster der er executed eller cancelled efter dato, og sikring at executed stadig er det, da faktura kan s�ttes tilbage.
412
                        $this->dbquery->setCondition("(date_executed >= \"".$date->get()."\" AND status = 2) OR (date_cancelled >= \"".$date->get()."\") OR status < 2");
413
                    }
414
                } else {
415
                    // Hvis der ikke er nogen dato så tager vi alle dem som p� nuv�rende tidspunkt har status under
416
                    $this->dbquery->setCondition("status < 2");
417
                }
418
            } else {
419
                switch ($this->dbquery->getFilter("status")) {
420
                    case "0":
421
                        $to_date_field = "date_created";
422
                        break;
423
424
                    case "1":
425
                        $to_date_field = "date_sent";
426
                        break;
427
428
                    case "2":
429
                        $to_date_field = "date_executed";
430
                        break;
431
432
                    case "3":
433
                        $to_date_field = "data_caneled";
434
                        break;
435
                }
436
437
                if ($this->dbquery->checkFilter("to_date")) {
438
                    $date = new Intraface_Date($this->dbquery->getFilter("to_date"));
439
                    if ($date->convert2db()) {
440
                        $this->dbquery->setCondition($to_date_field." <= \"".$date->get()."\"");
441
                    }
442
                } else {
443
                    // tager dem som på nuværende tidspunkt har den angivet status
444
                    $this->dbquery->setCondition("status = ".intval($this->dbquery->getFilter("status")));
445
                }
446
            }
447
        }
448
449
        $this->dbquery->setSorting("number DESC");
450
        $db = $this->dbquery->getRecordset("id", "", false);
451
452
        $list = array();
453
        while ($db->nextRecord()) {
454
            $reminder = new Reminder($this->kernel, $db->f("id"));
455
            $list[$i] = $reminder->get();
456
            if (is_object($reminder->contact->address)) {
457
                $list[$i]['contact_id'] = $reminder->contact->get('id');
458
                $list[$i]['name'] = $reminder->contact->address->get('name');
459
                $list[$i]['address'] = $reminder->contact->address->get('address');
460
                $list[$i]['postalcode'] = $reminder->contact->address->get('postcode');
461
                $list[$i]['city'] = $reminder->contact->address->get('city');
462
            }
463
            $i++;
464
        }
465
        return $list;
466
    }
467
468
    /**
469
     * Bruges ift. kontakter
470
     */