This repository has been archived by the owner on Jun 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
farm_grazing.paddocks.summary.inc
188 lines (153 loc) · 5.42 KB
/
farm_grazing.paddocks.summary.inc
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
<?php
/**
* @file
* Grazing paddock summary form.
*/
/**
* Paddock summary page callback.
*/
function farm_grazing_plan_summary_page($plan_obj) {
// Load utility functions.
module_load_include('inc', 'farm_grazing', 'farm_grazing.utils');
// get the plan id from the plan object
$plan = $plan_obj->id;
$wrapper = entity_metadata_wrapper('farm_plan', $plan);
$num_rotations = $wrapper->field_expected_rotations->value();
$grazing_growing_season = $wrapper->field_grazing_growing_season->value();
$days_of_drought_reserve = $wrapper->field_days_of_drought_reserve->value();
$start_ts = $wrapper->field_farm_date_range->value->value();
$end_ts = $wrapper->field_farm_date_range->value2->value();
$plan_days = floor(($end_ts - $start_ts) / 3600 / 24);
if ($grazing_growing_season) {
// Set the page title
drupal_set_title(t('Paddock Summary and Grazing Periods for Growing Season Plan'));
$table = array(
'header' => array(
t('Paddock'),
t('Area'),
t('Quality'),
t('Act. Min. Grazing Days'),
t('Act. Max. Grazing Days'),
),
'rows' => array(),
'empty' => t('No paddocks found.'),
);
$chk_min_recovery = -1;
$chk_max_recovery = -1;
$paddocks = farm_grazing_get_grazing_days_for_plan_id($plan, $chk_min_recovery, $chk_max_recovery, FALSE, TRUE);
$table['rows'] = $paddocks;
// markup
$form['text'] = array(
'#markup' => t('
<p>Check to see that recovery periods are adequate in paddocks with longer grazing periods.</p>
<h1>Actual Min/Max Grazing Periods</h1>
'),
);
$form['table'] = array(
'#markup' => theme('table', $table),
);
$form['summary']['check_min'] = array(
'#prefix' => '<p>',
'#markup' => t('Check Min. Recovery Period: ') . round($chk_min_recovery),
'#suffix' => '</p>',
);
$form['summary']['check_max'] = array(
'#prefix' => '<p>',
'#markup' => t('Check Max. Recovery Period: ') . round($chk_max_recovery),
'#suffix' => '</p>',
);
}
else {
// Set the page title
drupal_set_title(t('Paddock Summary and Grazing Periods for Non-Growing Season Plan'));
$table = array(
'header' => array(
t('Paddock'),
t('Area'),
t('ADA/H'),
t('Available ADs'),
t('Max. Grazing Days'),
t('Planned Harvest per Rotation (ADA)'),
t('Remaining ADA after First Rotation'),
t('Planned Total Harvest (ADA)'),
t('Forage Excess/Deficit (ADA) - Planned Drought Reserve'),
t('Available Drought ADs'),
t('Max. Drought Grazing Days'),
),
'rows' => array(),
'empty' => t('No paddocks found.'),
);
$paddocks = farm_grazing_get_non_growing_summary_for_plan_id($plan, FALSE, TRUE);
$table['rows'] = $paddocks;
$herd_size = farm_grazing_get_herd_size_in_sau($plan);
$num_paddocks = farm_grazing_get_paddock_count_for_plan($plan);
$tot_ads = empty($paddocks) ? 0 : $paddocks[$num_paddocks][3];
$avg_ads = $tot_ads / $num_paddocks;
$tot_grazing_days = $plan_days;
$est_carrying_capacity = $tot_ads / $tot_grazing_days;
$recovery_period = $tot_grazing_days / $num_rotations;
$grazing_period = $recovery_period / $num_paddocks;
$drought_reserve_grazing_period = $days_of_drought_reserve / $num_paddocks;
if ($herd_size > $est_carrying_capacity) {
drupal_set_message(t('Herd size is TOO BIG!'), 'error');
}
// markup
$form['text'] = array(
'#markup' => t('Paddock Summary for Non-Growing Season Plan'),
);
$form['table'] = array(
'#markup' => theme('table', $table),
);
$form['summary']['avg_ads'] = array(
'#prefix' => '<p>' . t('Average ADs: '),
'#markup' => round($avg_ads, 1),
'#suffix' => '</p>',
);
$form['summary']['tot_ads'] = array(
'#prefix' => '<p>' . t('Total AD Available: '),
'#markup' => $tot_ads,
'#suffix' => '</p>',
);
$form['summary']['tot_grazing_days'] = array(
'#prefix' => '<p>' . t('Total Grazing Days Required: '),
'#markup' => $tot_grazing_days,
'#suffix' => '</p>',
);
$form['summary']['herd_size'] = array(
'#prefix' => '<p>' . t('Herd Size (SAU): '),
'#markup' => $herd_size,
'#suffix' => '</p>',
);
$form['summary']['est_carrying_capacity'] = array(
'#prefix' => '<p>' . t('Estimated Carrying Capacity: '),
'#markup' => round($est_carrying_capacity, 1),
'#suffix' => '</p>',
);
$form['summary']['num_rotations'] = array(
'#prefix' => '<p>' . t('Number of Rotations: '),
'#markup' => $num_rotations,
'#suffix' => '</p>',
);
$form['summary']['recovery_period'] = array(
'#prefix' => '<p>' . t('Recovery Period: '),
'#markup' => round($recovery_period, 1),
'#suffix' => '</p>',
);
$form['summary']['num_paddocks'] = array(
'#prefix' => '<p>' . t('Number of Paddocks: '),
'#markup' => $num_paddocks,
'#suffix' => '</p>',
);
$form['summary']['grazing_period'] = array(
'#prefix' => '<p>' . t('Grazing Period: '),
'#markup' => round($grazing_period, 1),
'#suffix' => '</p>',
);
$form['summary']['drought_reserve_grazing_period'] = array(
'#prefix' => '<p>' . t('Drought Reserve Grazing Period (in days): '),
'#markup' => round($drought_reserve_grazing_period, 1),
'#suffix' => '</p>',
);
}
return $form;
}