return ['groupLabel' => $productClass->tip ?? 'other_items', 'price' => $price->price ?? 0, 'selfCost' => $selfCost->price ?? 0, 'quantity' => $balance->quantity ?? 0];
}
+ public function actionGetProductsWithRemains() {
+ Yii::$app->response->format = Response::FORMAT_JSON;
+ $storeGuid = Yii::$app->request->post('storeGuid');
+ $balance = ArrayHelper::map(Balances::find()->select(['quantity', 'product_id'])->where(['store_id' => $storeGuid])->all(), 'product_id', 'quantity');
+ $products = ArrayHelper::map(Products1c::find()->select(['id', 'name'])
+ ->where(['tip' => 'products'])->orderBy(['name' => SORT_ASC])->all(), 'id', 'name');
+ $result = [];
+ foreach ($products as $key => $name) {
+ if (isset($balance[$key])) {
+ $result[$key] = $name . ' - ' . $balance[$key];
+ }
+ }
+ return $result;
+ }
+
public function actionView($id)
{
if (Yii::$app->request->post()) {
const param24 = $('meta[name=csrf-param]').attr('content');
const token24 = $('meta[name=csrf-token]').attr('content');
+function updateProductsWithBalance(currentIndex, row) {
+ const store = $('#shifttransfer-store_guid');
+ const productGuid = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-product_guid');
+ productGuid.empty();
+ $.ajax({
+ type: 'POST',
+ url: '/shift-transfer/get-products-with-remains',
+ data: { storeGuid: store.val(), [param24]: token24 },
+ dataType: 'json',
+ success: (data) => {
+ console.log(data);
+ $.each(data, (key, el) => {
+ console.log(key, el)
+ const opt = document.createElement('option');
+ opt.text = el;
+ opt.value = key;
+ productGuid.append(opt);
+ })
+ }
+ });
+}
+
+function updateProductsWithBalanceAll() {
+ const rows = $('.multiple-input-list__item');
+ for (let currentIndex = 0; currentIndex < rows.length; currentIndex++) {
+ updateProductsWithBalance(currentIndex + 1, rows[currentIndex]);
+ }
+}
+
function checkInputRow(currentIndex, row, errorContainer) {
const productGuid = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-product_guid');
const productName = $(row).find('#select2-shifttransfer-shiftremainscopy-' + currentIndex + '-product_guid-container').text();
}
function setMultipleInputHandlers(currentIndex, row) {
+ updateProductsWithBalance(currentIndex, row);
const store = $('#shifttransfer-store_guid');
const groupLabel = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-group_label');
const productGuid = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-product_guid');