foreach ($products as $key => $data) {
if (isset($balance[$key]) && $balance[$key] > 0) {
$productGuids[$key] = $data['name'] . ' (арт. ' . $data['articule'] . ')';
- }
- else {
+ } else {
if (!$normal) {
$productGuids[$key] = $data['name'];
}
->andWhere(['shift_transfer_id' => $id])
->andWhere(['<', 'fact_and_1c_diff', 0])
->select('product_guid')->column()]),
- 'id', function($model) {
+ 'id', function ($model) {
return $model->name . ' (арт. ' . $model->articule . ')';
});
->select(['guid_replacement'])
->column()])
->all(),
- 'id', function($model) {
+ 'id', function ($model) {
return $model->name . ' (арт. ' . $model->articule . ')';
});
return Json::encode($data);
}
- public function actionGetMaxQuantity(string $productName, int $shiftTransferId)
+ public function actionGetMaxQuantity(string $productReplacementName, string $productName, int $shiftTransferId)
{
\Yii::$app->response->format = Response::FORMAT_JSON;
+ if (preg_match('/^[a-f0-9\-]{36}$/i', $productReplacementName)) {
+ $productReplacementId = $productReplacementName;
+ } else {
+ if (preg_match('/^(.*)\s\(арт\.\s(\d+)\)$/', $productReplacementName, $matches)) {
+ $productReplacementId = Products1c::findOne(['name' => $matches[1], 'articule' => $matches[2]])->id;
+ } else {
+ $productReplacementId = null;
+ }
+ }
+
if (preg_match('/^[a-f0-9\-]{36}$/i', $productName)) {
$productId = $productName;
} else {
}
$product = Products1c::findOne(['id' => $productId]);
+ $productReplacement = Products1c::findOne(['id' => $productReplacementId]);
if ($product) {
- $shiftRemain = ShiftRemains::findOne(['shift_transfer_id' => $shiftTransferId, 'product_guid' => $product->id]);
- if ($shiftRemain) {
+ $shiftRemainProduct = ShiftRemains::findOne(['shift_transfer_id' => $shiftTransferId, 'product_guid' => $product->id]);
+ $shiftRemainReplacement = ShiftRemains::findOne(['shift_transfer_id' => $shiftTransferId, 'product_guid' => $productReplacement->id]);
+ if ($shiftRemainProduct && $shiftRemainReplacement) {
return [
- 'maxValue' => $shiftRemain->fact_and_1c_diff ?? 0,
+ 'maxValue' => min(abs($shiftRemainProduct->fact_and_1c_diff), abs($shiftRemainReplacement->fact_and_1c_diff)) ?? 0,
];
}
return;
}
+
+ var productReplacementName = $('#shifttransfer-equalizationremains-' + rowId + '-product_id').val();
var productName = $('#shifttransfer-equalizationremains-' + rowId + '-product_replacement_id').val();
var shiftTransferId = getUrlParameter('id');
type: 'GET',
data: {
productName: productName,
+ productReplacementName: productReplacementName,
shiftTransferId: shiftTransferId
},
success: function (response) {
if (value > max) {
alert('Максимальное допустимое значение: ' + max);
- $(inputElement).val(max);
+ $(inputElement).val(max);
}
});