public function getCellFreeArea($cell)
 {
     $cellInfo = $this->getOneItem($cell);
     $freeArea = $cellInfo['area'];
     $cellProducts = $this->getCellProducts($cell);
     if ($cellProducts['total'] > 0) {
         $entity = EntityFactory::loadEntity('MeasureRates');
         foreach ($cellProducts['data'] as $product) {
             if ($product['remainder'] > 0) {
                 // Получаем кол-во поддонов на основании остатков. Остаток всегда в кг
                 $panNum = ceil($entity->getRatedValue(KG_MEASURE, P_MEASURE, $product['product_id'], $product['remainder']));
                 // Получаем текущую занимаемую площадь
                 $usedArea = ceil($entity->getRatedValue(P_MEASURE, M2_MEASURE, 0, $panNum));
                 $freeArea -= $usedArea;
             }
         }
     }
     return $freeArea;
 }
 public function getAllAvailable()
 {
     $select = $this->getTable() . '.*';
     $select .= ', products.title AS product_title';
     $select .= ', measures.title AS measure_title';
     $select .= ', factories.title AS factory_title';
     $select .= ', measures.short_title AS measure_short_title';
     $select .= ', users.fullname AS user';
     $select .= ', product_groups.title AS group_title';
     $select .= ', products.title AS product_title';
     $select .= ', factories_remainders.remainder AS remainder';
     $sql = 'SELECT ' . $select . ' FROM ' . $this->getTable();
     $sql .= ' INNER JOIN products ON (' . $this->getTable() . '.product_id = products.id)';
     $sql .= ' INNER JOIN measures ON (' . $this->getTable() . '.measure_id = measures.id)';
     $sql .= ' INNER JOIN factories ON (' . $this->getTable() . '.factory_id = factories.id)';
     $sql .= ' INNER JOIN users ON (' . $this->getTable() . '.user_id = users.id)';
     $sql .= ' INNER JOIN product_groups ON (products.group_id = product_groups.id)';
     $sql .= ' INNER JOIN factories_remainders ON (' . $this->getTable() . '.id = factories_remainders.product_factored_id)';
     $sql .= ' WHERE factories_remainders.remainder > 0';
     if ($filter = $this->getFilter()) {
         $sql .= ' AND ' . $filter;
     }
     $sql .= $this->getSort();
     $all = $this->getDb()->getAllAssoc($sql);
     if (!empty($all)) {
         $entity = EntityFactory::loadEntity('Remainders', 'factory');
         foreach ($all as $key => $product) {
             $all[$key]['date_formated'] = str_replace(' 00:00', '', $this->formatDate($all[$key]['factored_date']));
             $all[$key]['remainder'] = $entity->getCurrentRemainder($product['id'], $product['factory_id']);
         }
     }
     return array('data' => $all, 'total' => count($all));
 }
 public function moveToDcCells($request)
 {
     $data = array();
     foreach ($request['products'] as $moveProduct) {
         $errors = 0;
         $moveProduct['user_id'] = Auth::isLoggedIn();
         $entity = EntityFactory::loadEntity('ProductsFactored');
         $moveProduct['product_factored_id'] = $entity->getFactoredProduct($moveProduct['product_id'], $moveProduct['products_part']);
         // Пересчитываем кол-во в килограммы. Все остатки хранятся в кг.
         $entity = EntityFactory::loadEntity('MeasureRates');
         $quantityKg = $moveProduct['quantity'];
         if ($moveProduct['measure_id'] != KG_MEASURE) {
             if ($moveProduct['measure_id'] == GM_MEASURE || $moveProduct['measure_id'] == TN_MEASURE) {
                 $product = 0;
             } else {
                 $product = $moveProduct['product_id'];
             }
             $quantityKg = $entity->getRatedValue($moveProduct['measure_id'], KG_MEASURE, $product, $moveProduct['quantity']);
         }
         $entity = EntityFactory::loadEntity('Remainders', 'dc');
         $currentRemainder = $entity->getCurrentRemainder($moveProduct['product_factored_id'], $moveProduct['dc_id']);
         if ($currentRemainder < $quantityKg) {
             $errors++;
             $msg = 'Ошибка перемещения. Доступный остаток: ' . $currentRemainder . 'кг.';
         }
         if ($errors == 0) {
             $entity = EntityFactory::loadEntity('DcCells');
             $freeArea = $entity->getCellFreeArea($moveProduct['dc_cell_id']);
             // Получаем кол-во поддонов на основании остатков. Остаток всегда в кг
             $entity = EntityFactory::loadEntity('MeasureRates');
             $m2 = ceil($entity->getRatedValue(KG_MEASURE, P_MEASURE, $moveProduct['product_id'], $quantityKg));
             if ($freeArea < $m2) {
                 $errors++;
                 $msg = 'Ошибка перемещения. Недостаточно свободного места. (Свободно: ' . $freeArea . 'м²)';
             }
         }
         if ($errors == 0) {
             $entity = EntityFactory::loadEntity('Remainders', 'dc');
             $result = $entity->decreaseReminder($moveProduct);
             if (!$result) {
                 $errors++;
                 $msg = 'Ошибка перемещения.';
             } else {
                 $entity = EntityFactory::loadEntity('Remainders', 'dcCells');
                 $result = $entity->increaseReminder($moveProduct);
                 if (!$result) {
                     $errors++;
                     $msg = 'Ошибка перемещения.';
                 } else {
                     $msg = $moveProduct['quantity'] . ' ';
                     $msg .= $moveProduct['measure_short_title'] . ' ';
                     $msg .= $moveProduct['product_title'] . ' [' . $moveProduct['group_title'] . '] ';
                     $msg .= 'успешно перемещено в ';
                     $cellTitle = substr($moveProduct['dc_cell_title'], 0, strpos($moveProduct['dc_cell_title'], ' ('));
                     $msg .= $cellTitle . ' [' . $moveProduct['dc_store_title'] . '] ';
                 }
             }
         }
         if ($errors > 0) {
             $data['is_error'] = true;
         } else {
             $data['is_error'] = false;
         }
         $data['messages'][] = $msg;
     }
     return $data;
 }
Exemple #4
0
<?php

if (!defined('KERNEL_LOADED')) {
    die;
}
require_once ENTITIES_COMPONENTS_DIR . 'EntityFactory.php';
$entity = EntityFactory::loadEntity('Products');
$cmd = !empty($_REQUEST['cmd']) ? $_REQUEST['cmd'] : 'getGrid';
if ($cmd == 'getGrouped' && !empty($_REQUEST['group_selected'])) {
    $data = $entity->getGroupedBy('group_id', intval($_REQUEST['group_selected']));
} else {
    $data = EntityFactory::processRequest($cmd);
}
echo json_encode($data);
Exemple #5
0
<?php

if (!defined('KERNEL_LOADED')) {
    die;
}
require_once ENTITIES_COMPONENTS_DIR . 'EntityFactory.php';
$entity = EntityFactory::loadEntity('Cities');
$cmd = !empty($_REQUEST['cmd']) ? $_REQUEST['cmd'] : 'getGrid';
$data = EntityFactory::processRequest($cmd);
echo json_encode($data);
Exemple #6
0
$entity = EntityFactory::loadEntity('Cells');
$cmd = !empty($_REQUEST['cmd']) ? $_REQUEST['cmd'] : 'getGrid';
if (($cmd == 'getAffStoreCells' || $cmd == 'getAvailableAffStoreCells') && !empty($_REQUEST['aff_store_id'])) {
    $data = $entity->getGroupedBy('aff_store_id', intval($_REQUEST['aff_store_id']));
} else {
    $data = EntityFactory::processRequest($cmd);
}
if ($cmd == 'getGrid' || $cmd == 'getAffStoreCells' || $cmd == 'getAvailableAffStoreCells') {
    if ($data['total'] > 0) {
        $entity = EntityFactory::loadEntity('MeasureRates');
        foreach ($data['data'] as $key => $cell) {
            $data['data'][$key]['free_area'] = $cell['area'];
            $entity = EntityFactory::loadEntity('Cells');
            $cellProducts = $entity->getCellProducts($cell['id']);
            if ($cellProducts['total'] > 0) {
                $entity = EntityFactory::loadEntity('MeasureRates');
                foreach ($cellProducts['data'] as $product) {
                    if ($product['remainder'] > EntityFactory::getSetting('min_reminder')) {
                        // Получаем кол-во поддонов на основании остатков. Остаток всегда в кг
                        $panNum = ceil($entity->getRatedValue(KG_MEASURE, P_MEASURE, $product['product_id'], $product['remainder']));
                        // Получаем текущую занимаемую площадь
                        $usedArea = ceil($entity->getRatedValue(P_MEASURE, M2_MEASURE, 0, $panNum));
                        $data['data'][$key]['free_area'] -= $usedArea;
                    }
                }
            }
        }
        // Убираем полностью занятые камеры из выпадающего списка.
        if ($cmd == 'getAvailableAffStoreCells') {
            $info = $data['data'];
            $data = array();
Exemple #7
0
<?php

if (!defined('KERNEL_LOADED')) {
    die;
}
require_once ENTITIES_COMPONENTS_DIR . 'EntityFactory.php';
$entity = EntityFactory::loadEntity('Carriers');
$cmd = !empty($_REQUEST['cmd']) ? $_REQUEST['cmd'] : 'getGrid';
$data = EntityFactory::processRequest($cmd);
echo json_encode($data);
<?php

if (!defined('KERNEL_LOADED')) {
    die;
}
require_once ENTITIES_COMPONENTS_DIR . 'EntityFactory.php';
$cmd = 'getGrid';
$direction = !empty($_REQUEST['direction_selected']) ? $_REQUEST['direction_selected'] : 'ac';
$recipientType = substr($direction, 1);
switch ($recipientType) {
    case 'f':
        // Список комбинатов
        EntityFactory::loadEntity('Factories');
        break;
    case 'd':
        // Список РЦ
        EntityFactory::loadEntity('DC');
        break;
    case 'c':
        // Список клиентов
        EntityFactory::loadEntity('Clients');
        break;
    case 'a':
        // Список филиалов
    // Список филиалов
    default:
        EntityFactory::loadEntity('Affiliates');
        break;
}
$data = EntityFactory::processRequest($cmd);
echo json_encode($data);
<?php

if (!defined('KERNEL_LOADED')) {
    die;
}
require_once ENTITIES_COMPONENTS_DIR . 'EntityFactory.php';
$entity = EntityFactory::loadEntity('Factories');
$cmd = !empty($_REQUEST['cmd']) ? $_REQUEST['cmd'] : 'getGrid';
$data = EntityFactory::processRequest($cmd);
echo json_encode($data);
<?php

if (!defined('KERNEL_LOADED')) {
    die;
}
require_once ENTITIES_COMPONENTS_DIR . 'EntityFactory.php';
$entity = EntityFactory::loadEntity('CarriersVehicles');
$cmd = !empty($_REQUEST['cmd']) ? $_REQUEST['cmd'] : 'getGrid';
if ($cmd == 'getGrouped' && !empty($_REQUEST['carrier_id'])) {
    $data = $entity->getGroupedBy('carrier_id', intval($_REQUEST['carrier_id']));
} else {
    $data = EntityFactory::processRequest($cmd);
}
echo json_encode($data);
Exemple #11
0
                            case 'f':
                                $recRemindersType = 'factory';
                                $productTrack['factory_id'] = $productTrack['to_id'];
                                break;
                            case 'd':
                                $recRemindersType = 'dc';
                                $productTrack['dc_id'] = $productTrack['to_id'];
                                break;
                            case 'a':
                                $recRemindersType = 'affiliate';
                                $productTrack['aff_id'] = $productTrack['to_id'];
                                break;
                            default:
                                break;
                        }
                        $entity = EntityFactory::loadEntity('Remainders', $recRemindersType);
                        $entity->increaseReminder($productTrack);
                    }
                }
            }
        }
    } else {
        $errors++;
        $data['messages'][] = 'Записи не выбраны.';
    }
    if ($errors > 0) {
        $data['is_error'] = true;
    } else {
        $data['is_error'] = false;
    }
} else {
Exemple #12
0
<?php

if (!defined('KERNEL_LOADED')) {
    die;
}
require_once ENTITIES_COMPONENTS_DIR . 'EntityFactory.php';
$entity = EntityFactory::loadEntity('Users');
$errors = 0;
$cmd = !empty($_REQUEST['cmd']) ? $_REQUEST['cmd'] : 'getGrid';
if ($cmd == 'resetpwd') {
    $defaultPass = '******';
    die($defaultPass);
}
if ($cmd == 'block' || $cmd == 'unblock') {
    $ids = !empty($_REQUEST['ids']) ? json_decode($_REQUEST['ids']) : null;
    if (is_array($ids) && !empty($ids)) {
        foreach ($ids as $id) {
            if ($cmd == 'block') {
                $result = $entity->block($id);
                if (!$result) {
                    $errors++;
                    $msg = 'Ошибка блокировки.';
                } else {
                    $msg = 'Пользователи успешно заблокированы.';
                }
            } elseif ($cmd == 'unblock') {
                $result = $entity->unblock($id);
                if (!$result) {
                    $errors++;
                    $msg = 'Ошибка разблокировки.';
                } else {
 protected function updateRemainders($request, $operation)
 {
     if (is_numeric($request['quantity'])) {
         $request['remainder'] = $request['quantity'];
         $request['datetime_modified'] = strtotime('now');
         // Пересчитываем кол-во в килограммы. Все остатки хранятся в кг.
         if ($request['measure_id'] != KG_MEASURE) {
             if ($request['measure_id'] == GM_MEASURE || $request['measure_id'] == TN_MEASURE) {
                 $product = 0;
             } else {
                 $product = $request['product_id'];
             }
             $entity = EntityFactory::loadEntity('MeasureRates');
             $request['remainder'] = $entity->getRatedValue($request['measure_id'], KG_MEASURE, $product, $request['quantity']);
         }
         // Проверяем наличие текущего остатка
         $current = $this->getCurrentRemainder($request['product_factored_id'], $request[$this->_recipientsField]);
         if ($current === null) {
             // Нет записи в БД. Добавляем новый остаток.
             if ($this->add($request)) {
                 return true;
             }
         } else {
             // Обновляем текущий остаток. (Текущий остаток может быть >= 0)
             $action = $operation == 'add' ? '+' : '-';
             $sql = 'UPDATE ' . $this->getTable() . ' SET remainder=remainder' . $action . $request['remainder'];
             $sql .= ', datetime_modified=' . $request['datetime_modified'];
             $sql .= ' WHERE product_factored_id=' . intval($request['product_factored_id']);
             $sql .= ' AND ' . $this->_recipientsField . '=' . intval($request[$this->_recipientsField]);
             if ($this->getDb()->query($sql)) {
                 return true;
             }
         }
     }
 }
<?php

if (!defined('KERNEL_LOADED')) {
    die;
}
require_once ENTITIES_COMPONENTS_DIR . 'EntityFactory.php';
$entity = EntityFactory::loadEntity('ProductGroups');
$cmd = !empty($_REQUEST['cmd']) ? $_REQUEST['cmd'] : 'getGrid';
$data = EntityFactory::processRequest($cmd);
echo json_encode($data);
<?php

if (!defined('KERNEL_LOADED')) {
    die;
}
require_once ENTITIES_COMPONENTS_DIR . 'EntityFactory.php';
$entity = EntityFactory::loadEntity('Directions');
$cmd = !empty($_REQUEST['cmd']) ? $_REQUEST['cmd'] : 'getGrid';
switch ($cmd) {
    case 'getDirections_F':
        $start = 'f';
        break;
    case 'getDirections_D':
        $start = 'd';
        break;
    case 'getDirections_C':
        $start = 'c';
        break;
    case 'getDirections_A':
    default:
        $start = 'a';
        break;
}
$data = $entity->getAllFiltered($start);
echo json_encode($data);
<?php

if (!defined('KERNEL_LOADED')) {
    die;
}
require_once ENTITIES_COMPONENTS_DIR . 'EntityFactory.php';
$entity = EntityFactory::loadEntity('UserGroups');
$cmd = !empty($_REQUEST['cmd']) ? $_REQUEST['cmd'] : 'getGrid';
$data = EntityFactory::processRequest($cmd);
echo json_encode($data);
<?php

if (!defined('KERNEL_LOADED')) {
    die;
}
require_once ENTITIES_COMPONENTS_DIR . 'EntityFactory.php';
$cmd = !empty($_REQUEST['cmd']) ? $_REQUEST['cmd'] : 'getGrid';
$placeType = 'dc';
if (!empty($_REQUEST['from_cell_id'])) {
    $placeType = 'dcCells';
    $place = $_REQUEST['from_cell_id'];
} elseif (!empty($_REQUEST['dc_id'])) {
    $place = $_REQUEST['dc_id'];
}
$entity = EntityFactory::loadEntity('Remainders', $placeType);
if ($cmd == 'getAvailableGroups' && $place) {
    $data = $entity->getAvailableGroups($place);
} elseif ($cmd == 'getAvailableProducts' && $place) {
    $data = $entity->getAvailableProducts($place, $_REQUEST['group_id']);
} elseif ($cmd == 'getAvailableParts' && $place) {
    $data = $entity->getAvailableParts($place, $_REQUEST['product_id']);
} else {
    $data = EntityFactory::processRequest($cmd);
}
echo json_encode($data);
Exemple #18
0
<?php

if (!defined('KERNEL_LOADED')) {
    die;
}
require_once ENTITIES_COMPONENTS_DIR . 'EntityFactory.php';
$entity = EntityFactory::loadEntity('Settings');
$cmd = !empty($_REQUEST['cmd']) ? $_REQUEST['cmd'] : 'getGrid';
// TODO:
//if ($cmd == 'edit' && !empty($_REQUEST['f'])) {
//	$f = $_REQUEST['f'];
//	unset($_REQUEST['f']['key']);
//	if ($f['key'] == 'date_format') {
//		$dateValue = strtolower($f['value']);
//		$_REQUEST['f']['value'] = $dateFormat.' H:i';
//	}
//}
$data = EntityFactory::processRequest($cmd);
echo json_encode($data);
Exemple #19
0
<?php

if (!defined('KERNEL_LOADED')) {
    die;
}
require_once ENTITIES_COMPONENTS_DIR . 'EntityFactory.php';
$entity = EntityFactory::loadEntity('DC');
$cmd = !empty($_REQUEST['cmd']) ? $_REQUEST['cmd'] : 'getGrid';
$data = EntityFactory::processRequest($cmd);
echo json_encode($data);
Exemple #20
0
<?php

if (!defined('KERNEL_LOADED')) {
    die;
}
require_once ENTITIES_COMPONENTS_DIR . 'EntityFactory.php';
$entity = EntityFactory::loadEntity('Countries');
$cmd = !empty($_REQUEST['cmd']) ? $_REQUEST['cmd'] : 'getGrid';
$data = EntityFactory::processRequest($cmd);
echo json_encode($data);
Exemple #21
0
<?php

if (!defined('KERNEL_LOADED')) {
    die;
}
require_once ENTITIES_COMPONENTS_DIR . 'EntityFactory.php';
$entity = EntityFactory::loadEntity('Clients');
$cmd = !empty($_REQUEST['cmd']) ? $_REQUEST['cmd'] : 'getGrid';
$data = EntityFactory::processRequest($cmd);
echo json_encode($data);
<?php

if (!defined('KERNEL_LOADED')) {
    die;
}
require_once ENTITIES_COMPONENTS_DIR . 'EntityFactory.php';
$cmd = !empty($_REQUEST['cmd']) ? $_REQUEST['cmd'] : 'getGrid';
$entity = EntityFactory::loadEntity('Remainders', 'cells');
if ($cmd == 'getAvailableGroups') {
    $data = $entity->getAvailableGroups($_REQUEST['cell_id']);
} elseif ($cmd == 'getAvailableProducts') {
    $data = $entity->getAvailableProducts($_REQUEST['cell_id'], $_REQUEST['group_id']);
} elseif ($cmd == 'getAvailableParts') {
    $data = $entity->getAvailableParts($_REQUEST['cell_id'], $_REQUEST['product_id']);
} elseif ($cmd == 'getGrid') {
    $data = $entity->getCellsRemainders();
} else {
    $data = EntityFactory::processRequest($cmd);
}
echo json_encode($data);
<?php

if (!defined('KERNEL_LOADED')) {
    die;
}
require_once ENTITIES_COMPONENTS_DIR . 'EntityFactory.php';
$cmd = !empty($_REQUEST['cmd']) ? $_REQUEST['cmd'] : 'getGrid';
$possibleDirections = array('ff', 'fd', 'fa', 'fc');
$entity = EntityFactory::loadEntity('ProductsMovement', $possibleDirections);
if (!empty($_REQUEST['f']) && $cmd == 'ship') {
    foreach ($_REQUEST['f']['products'] as $key => $request) {
        $_REQUEST['f']['products'][$key]['factory_id'] = $_REQUEST['f']['factory_id'];
        $_REQUEST['f']['products'][$key]['factory_title'] = $_REQUEST['f']['factory_title'];
    }
    $data = $entity->shipProducts($_REQUEST['f']);
} else {
    $data = EntityFactory::processRequest($cmd);
    if ($cmd == 'getGrid') {
        foreach ($data['data'] as $key => $val) {
            if ($val['direction'] == 'fd' && empty($val['from_id'])) {
                unset($data['data'][$key]);
                $data['total']--;
            }
        }
    }
}
echo json_encode($data);
        $data['messages'][] = 'На складе нет столько товара. Текущий остаток: ' . $currentReminder . ' кг.';
    } else {
        $entity->edit(array('id' => $_REQUEST['f']['id'], 'datetime_modified' => strtotime('now'), 'remainder' => $currentReminder - $ratedShippedValue));
        // Сохраняем информацию об отгрузке
        $_REQUEST['f']['user_id'] = Auth::isLoggedIn();
        $_REQUEST['f']['datetime'] = strtotime('now');
        $_REQUEST['f']['stored_product_id'] = $_REQUEST['f']['id'];
        $entity = EntityFactory::loadEntity('ProductShipped');
        $result = $entity->shipProduct($_REQUEST['f']);
        if (!$result || is_string($result)) {
            $errors++;
            $msg = 'Ошибка отгрузки';
            if (is_string($result)) {
                $msg .= ': ' . $result;
            }
            $msg .= '.';
        } else {
            $msg = 'Товар успешно отгружен.';
        }
        if ($errors > 0) {
            $data['is_error'] = true;
        } else {
            $data['is_error'] = false;
        }
        $data['messages'][] = $msg;
    }
} else {
    $entity = EntityFactory::loadEntity('ProductShipped');
    $data = EntityFactory::processRequest($cmd);
}
echo json_encode($data);