1
- <?php
2
-
3
- declare (strict_types=1 );
1
+ <?php declare (strict_types=1 );
4
2
5
3
namespace hipanel \modules \stock \grid ;
6
4
7
5
use DateTimeImmutable ;
8
6
use hipanel \grid \MainColumn ;
9
7
use hipanel \modules \stock \models \Part ;
10
- use hipanel \widgets \Label ;
11
8
use yii \helpers \Html ;
12
9
use Yii ;
13
10
@@ -21,28 +18,40 @@ public function init(): void
21
18
if (Yii::$ app ->user ->can ('model.read ' )) {
22
19
$ modelLabel = Html::a ($ modelLabel , ['@model/view ' , 'id ' => $ model ->model_id ]);
23
20
}
21
+ $ id = implode ('- ' , ['model ' , $ model ->id ]);
24
22
if (isset ($ model ->warranty_till )) {
25
- $ modelLabel .= $ this ->getWarrantyLabel ($ model );
23
+ [$ warranty , $ color ] = $ this ->getWarranty ($ model );
24
+ $ this ->grid ->view ->registerCss ("span# $ id > a::after {
25
+ content: ' $ warranty';
26
+ background-color: $ color;
27
+ color: white;
28
+ font-weight: bold;
29
+ font-size: 12px;
30
+ margin-left: 5px;
31
+ padding: 3px 5px;
32
+ border-radius: 3px;
33
+ box-shadow: 2px 2px rgba(0, 0, 0, 0.1);
34
+ } " );
26
35
}
27
36
28
- return $ modelLabel ;
37
+ return Html:: tag ( ' span ' , $ modelLabel, [ ' id ' => $ id , ' style ' => ' display: inline-block; ' ]) ;
29
38
};
30
39
}
31
40
32
- private function getWarrantyLabel (Part $ model ): string
41
+ private function getWarranty (Part $ model ): array
33
42
{
34
43
$ diffTime = date_diff (new DateTimeImmutable (), new DateTimeImmutable ($ model ->warranty_till ));
35
44
$ diff = (int )$ diffTime ->format ('%y ' ) * 12 + (int )$ diffTime ->format ('%m ' );
36
45
$ diff = ($ diffTime ->invert === 1 ) ? $ diff * -1 : $ diff ;
37
46
$ diff = ($ diff <= 0 ) ? 'X ' : $ diff ;
38
- $ color = 'info ' ;
47
+ $ color = 'deepskyblue ' ;
39
48
if ($ diff <= 6 ) {
40
- $ color = 'warning ' ;
49
+ $ color = 'salmon ' ;
41
50
}
42
51
if (!is_numeric ($ diff )) {
43
- $ color = 'danger ' ;
52
+ $ color = 'crimson ' ;
44
53
}
45
54
46
- return Label:: widget ([ ' label ' => $ diff , ' tag ' => ' sup ' , ' color ' => $ color ]) ;
55
+ return [ $ diff , $ color ];
47
56
}
48
57
}
0 commit comments