$model->load(Yii::$app->request->get());
+ $isEditable = date($model->year . '-' . $model->month . '-d') > date('Y-m-d') && (
+ (date('d') < 25) ||
+ (date('Y-m-d', strtotime('-1 month', date($model->year . '-' . $model->month . '-d'))) > date('Y-m-d')
+ ));
+//var_dump($isEditable); die;
+
$prevPrevMonthStart = date("Y-m-01", strtotime("-2 month", strtotime($model->year . "-" . $model->month . "-01")));
$prevPrevMonthEnd = date("Y-m-t", strtotime("-2 month", strtotime($model->year . "-" . $model->month . "-01")));
$stores = $query->all();
return $this->render('index', compact('model', 'years', 'stores',
- 'salesWriteOffsPlan', 'sales'));
+ 'salesWriteOffsPlan', 'sales', 'isEditable'));
}
public function actionSaveFields() {
/* @var $stores array */
/* @var $salesWriteOffsPlan SalesWriteOffsPlan[] */
/* @var $sales array */
+/* @var $isEditable boolean */
$this->registerJsFile('/js/sales-write-offs-plan/index.js', ['position' => \yii\web\View::POS_END]);
input[type=number], [name=total_sales_plan] {
max-width: 100px;
}
+input[readonly] {
+ background: lightgray;
+}
');
function colorScheme1($p) {
?>
<tr>
<td><?= $store->name ?><?= Html::hiddenInput('store_id', $store->id) ?></td>
- <td><?= Html::textInput('total_sales_plan', $total_sales_plan, ['readonly' => true, 'style' => 'background: lightgray;']) ?></td>
+ <td><?= Html::textInput('total_sales_plan', $total_sales_plan, ['readonly' => true]) ?></td>
<td>
<?= Html::hiddenInput('total_sales_fact', $total_sales_fact) ?>
<span class="p1" style="color:<?= colorScheme1($p1) ?>">
<?= number_format(round($p1 * 100), 0, '.', ' ') ?>
</span>%
</td>
- <td><?= Html::textInput('write_offs_plan', $write_offs_plan, ['type' => 'number', 'min' => 0, 'onchange' => 'editField(this);']) ?></td>
+ <td><?= Html::textInput('write_offs_plan', $write_offs_plan, ['type' => 'number', 'min' => 0, 'readonly' => !$isEditable, 'onchange' => 'editField(this);']) ?></td>
<td>
<span class="p2" style="color:<?= colorScheme2($p2) ?>">
<?= number_format(round($p2 * 100), 1, '.', ' ') ?>
</span>%
</td>
- <td><?= Html::textInput('offline_sales_plan', $offline_sales_plan, ['type' => 'number', 'min' => 0, 'onchange' => 'editField(this);']) ?></td>
+ <td><?= Html::textInput('offline_sales_plan', $offline_sales_plan, ['type' => 'number', 'min' => 0, 'readonly' => !$isEditable, 'onchange' => 'editField(this);']) ?></td>
<td>
<span class="p3" style="color:<?= colorScheme1($p3) ?>">
<?= number_format(round($p3 * 100), 0, '.', ' ') ?>
</span>%
</td>
- <td><?= Html::textInput('online_sales_shop_plan', $online_sales_shop_plan, ['type' => 'number', 'min' => 0, 'onchange' => 'editField(this);']) ?></td>
+ <td><?= Html::textInput('online_sales_shop_plan', $online_sales_shop_plan, ['type' => 'number', 'min' => 0, 'readonly' => !$isEditable, 'onchange' => 'editField(this);']) ?></td>
<td>
<span class="p4" style="color:<?= colorScheme1($p4) ?>">
<?= number_format(round($p4 * 100), 0, '.', ' ') ?>
</span>%
</td>
- <td><?= Html::textInput('online_sales_marketplace_plan', $online_sales_marketplace_plan, ['type' => 'number', 'min' => 0, 'onchange' => 'editField(this);']) ?></td>
+ <td><?= Html::textInput('online_sales_marketplace_plan', $online_sales_marketplace_plan, ['type' => 'number', 'min' => 0, 'readonly' => !$isEditable, 'onchange' => 'editField(this);']) ?></td>
<td>
<span class="p5" style="color:<?= colorScheme1($p5) ?>">
<?= number_format(round($p5 * 100), 0, '.', ' ') ?>