/**
  * @param $purchase_id
  * @return array
  */
 public static function getOrdersCollectionsByPurchaseIdAndByUserId($purchase_id, $user_id)
 {
     $orders = \DB::table(\App\Basket::TABLE_PRODUCTS_IN_BASKETS)->select('*')->where('user_id', '=', $user_id)->where('purchase_id', '=', $purchase_id)->get();
     $user = \App\User::find($user_id);
     \App\Helpers\Assistant::assertModel($user);
     $orders_models = $user->orders()->where('purchase_id', '=', $purchase_id)->get();
     if (!$orders_models->count()) {
         return [];
     }
     $orders_collections_arr = [];
     foreach ($orders_models as $order_model) {
         $order_collection = new \stdClass();
         $order_collection->order_id = $order_model->id;
         $order_collection->amount = $order_model->amount;
         $order_collection->purchase_id = $order_model->purchase_id;
         $order_collection->product_id = $order_model->product_id;
         $order_collection->product_in_purchase_id = $order_model->product_in_purchase_id;
         $product_in_purchase_model = \App\Models\ProductInPurchaseModel::find($order_model->product_in_purchase_id);
         \App\Helpers\Assistant::assertModel($product_in_purchase_model);
         $current_max_price = $product_in_purchase_model->getMaxPrice();
         $order_collection->product_price = $current_max_price;
         $order_collection->total_price = number_format(\App\Helpers\OrdersHelper::getTotalPrice($current_max_price, $order_model->amount), 2);
         $order_collection->product_name = $product_in_purchase_model->product->name;
         $order_collection->product_alias = $product_in_purchase_model->alias();
         $orders_collections_arr[] = $order_collection;
     }
     return $orders_collections_arr;
 }
 public function getPricingGrids($supplier_id)
 {
     $supplier_model = $this->user->suppliers()->find($supplier_id);
     \App\Helpers\Assistant::assertModel($supplier_model);
     $products_models_arr = $supplier_model->products()->paginate(50);
     return view('seller.suppliers.pricing-grids', ['supplier_model' => $supplier_model, 'goods_models_arr' => $products_models_arr]);
 }
 /**
  * Возвращает текущую максимальную цену
  * @return float
  */
 public function getCurrentMaxPrice()
 {
     $current_max_pricing_grid_column_id = $this->purchase->getCurrentMaxPricingGridColumnId();
     $price_obj = \DB::table('prices')->where('product_id', '=', $this->getProduct()->id)->where('column_id', '=', $current_max_pricing_grid_column_id)->first();
     if (!$price_obj) {
         \App\Helpers\Assistant::exception("Не указана цена для продукта {$this->getProduct()->id} в колонке {$current_max_pricing_grid_column_id}");
         return 0;
     }
     return $price_obj->price;
 }
 /**
  * Удаление заказа
  * @param $order_id
  * @return bool
  */
 public function deleteOrder($order_id)
 {
     \App\Helpers\Assistant::assertUserAsJson($this->user);
     $order = $this->user->orders()->find($order_id);
     if (!$order) {
         return false;
     }
     $order->delete();
     return true;
 }
 /**
  * Создание транзакции Поступление средств
  * @param double $sum
  * @param \App\User $user
  * @return \App\BusinessLogic\Models\PaymentTransaction
  */
 public static function makeAdmission($sum, \App\User $user)
 {
     \App\Helpers\Assistant::assertUserAsJson($user);
     // Начало транзакции БД
     \DB::beginTransaction();
     $payment_transaction = self::create(['sum' => $sum, 'user_id' => $user->id, 'operation_type' => self::OPERATION_TYPE_ADMISSION, 'operation_type_code' => self::OPERATION_TYPE_ADMISSION_CODE]);
     \App\ActionLog::action('PAYMENT_TRANSACTION.BLOCKING', ['payment_transaction_id' => $payment_transaction->id, 'sum' => $sum, 'user_id' => $user->id, 'operation_type' => self::OPERATION_TYPE_ADMISSION, 'operation_type_code' => self::OPERATION_TYPE_ADMISSION_CODE]);
     \DB::commit();
     // Окончание транзакции БД
     return $payment_transaction;
 }
 public function getProduct($alias = null)
 {
     if (empty($alias)) {
         return response(view('errors.product_404'), 404);
     }
     $product_id = \App\Helpers\PurchaseHelper::getProductIdByAlias($alias);
     $product_model = \App\BusinessLogic\Models\Product::find($product_id);
     \App\Helpers\Assistant::assertModel($product_model);
     $purchase_id = \App\Helpers\PurchaseHelper::getPurchaseIdByAlias($alias);
     $purchase_model = \App\BusinessLogic\Models\Purchase::find($purchase_id);
     \App\Helpers\Assistant::assertModel($purchase_model);
     //$product_in_purchase = \App\Models\ProductInPurchaseModel::findByProductIdAndByPurchaseId($product_id, $purchase_id);
     $product_in_purchase = new \App\Services\BusinessLogic\Models\ProductInPurchase($product_model, $purchase_model);
     //    \App\Models\AttendanceCounterModel::enrol($product_in_purchase->id, \App\Models\AttendanceCounterModel::TARGET_TYPE_PRODUCT_IN_PURCHASE);
     if (!$product_model or !$purchase_model) {
         return response(view('errors.product_404'), 404);
     }
     return view('product.card', ['product_in_purchase' => $product_in_purchase]);
 }
 /**
  * Возвращает модели ценовых колонок в порядке роста цен, предварительно проверив корректность ценовых диапазонов
  * @return array
  * @throws \Exception
  */
 public function columns()
 {
     $columns_models = $this->hasMany('\\App\\Models\\PricingGridColumnModel', 'pricing_grid_id')->orderBy('min_sum');
     if (!$columns_models->count()) {
         return [];
     }
     $columns_models_arr = [];
     $last_max_sum = 0;
     foreach ($columns_models->get() as $column_model) {
         $current_min_sum = doubleval($column_model->min_sum);
         $current_max_sum = doubleval($column_model->max_sum);
         if ($current_min_sum >= $current_max_sum) {
             \App\Helpers\Assistant::exception('Неверные значения цен (>=) в колонке ID#' . $column_model->id . ' для ценовой сетки ID#' . $this->id);
         }
         if ($current_min_sum != $last_max_sum) {
             //    \App\Helpers\Assistant::exception('Неверные значения цен (!=) в колонке ID#' . $column_model->id . ' для ценовой сетки ID#' . $this->id);
         }
         $last_max_sum = $current_max_sum;
         $columns_models_arr[] = $column_model;
     }
     return $columns_models_arr;
 }
Esempio n. 8
0
 /**
  * Возвращает текущую максимальную цену
  * @param $purchase_id
  * @return float
  * @throws \Exception
  */
 public function getCurrentMaxPriceForPurchase($purchase_id)
 {
     $purchase = \App\BusinessLogic\Models\Purchase::find($purchase_id);
     \App\Helpers\Assistant::assertModel($purchase);
     $current_max_pricing_grid_column_id = $purchase->getCurrentMaxPricingGridColumnId();
     $price_obj = \DB::table('prices')->where('product_id', '=', $this->id)->where('column_id', '=', $current_max_pricing_grid_column_id)->first();
     if (!$price_obj) {
         \App\Helpers\Assistant::exception("Не указана цена для продукта {$this->id} в колонке {$current_max_pricing_grid_column_id}");
         return 0;
     }
     return doubleval($price_obj->price);
 }
$project_id = 1;
$project = \App\Models\ProjectModel::find($project_id);
$categories_models = \App\Helpers\ProjectHelper::getCategoriesByProjectId($project_id);
$attributes_group_id = \App\Helpers\ProjectHelper::getDefaultAttributesGroupId();
$attributes = \App\Models\AttributeModel::where('attribute_group_id', '=', $attributes_group_id)->get();
?>

<div class="container">
    <div class="row">
        <div class="col-md-12">
            <?php 
$supplier_id = \Input::get('supplier_id');
$supplier_model = null;
if ($supplier_id) {
    $supplier_model = $user->suppliers()->find($supplier_id);
    \App\Helpers\Assistant::assertModel($supplier_model);
}
?>

            <div class="btn-toolbar" role="toolbar" style="padding: 10px 0;">
                <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#editProduct">
                    Добавить товар
                </button>
            </div>

            <table class="table table-condensed table-striped table-hover table-bordered">
                <thead>
                <tr>
                    <th style="width: 50px">ID</th>
                    <th style="width: 34px"></th>
                    <th>Товар</th>
Esempio n. 10
0
 /**
  * Изменение объема(количества продуктов) заказа
  * @param $amount
  * @return $this|null
  * @throws \Exception
  */
 public function updateAmount($amount)
 {
     $amount = intval($amount);
     if ($amount < 1) {
         $this->_delete();
         return null;
     }
     if ($amount === intval($this->amount)) {
         return $this;
     }
     $product = $this->product;
     \App\Helpers\Assistant::assertModel($product);
     $current_max_price_for_purchase = $product->getCurrentMaxPriceForPurchase($this->purchase_id);
     $sum = $current_max_price_for_purchase * $amount;
     \App\ActionLog::action('ORDER.UPDATE.BEFORE_TRANSACTION', ['order_id' => $this->id, 'current_max_price_for_purchase' => $current_max_price_for_purchase, 'purchase_id' => $this->purchase_id, 'product_id' => $this->product_id, 'amount' => $amount, 'sum' => $sum]);
     // Начало транзакции БД
     \DB::beginTransaction();
     $current_payment_transaction = $this->getCurrentPaymentTransaction();
     $current_payment_transaction->unblocking();
     $this->moneyBlocking($sum);
     $this->amount = $amount;
     $this->save();
     \DB::commit();
     // Окончание транзакции БД
     \App\ActionLog::action('ORDER.UPDATE.AFTER_TRANSACTION', ['order_id' => $this->id, 'current_max_price_for_purchase' => $current_max_price_for_purchase, 'purchase_id' => $this->purchase_id, 'product_id' => $this->product_id, 'amount' => $amount, 'sum' => $sum]);
     return $this;
 }
Esempio n. 11
0
                                <div class="panel-body">
                                    <table class="table">
                                        <thead>
                                        <tr>
                                            <th>Товар</th>
                                            <th>Цена*</th>
                                            <th>Количество</th>
                                            <th>Сумма</th>
                                            <th></th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        @foreach($orders_models_arr_by_purchases_ids_arr[$purchase_id] as $order_model)
                                        <?php 
$product_in_purchase_model = \App\Models\ProductInPurchaseModel::find($order_model->product_in_purchase_id);
\App\Helpers\Assistant::assertModel($product_in_purchase_model);
$current_max_price = $product_in_purchase_model->getMaxPrice();
?>
                                        <tr id="orderValue-{{ $order_model->id }}">
                                            <td><a href="{{ $product_in_purchase_model->alias() }}">{{ $product_in_purchase_model->product->name }}</a></td>
                                            <td class="product-price">{{ $current_max_price }}</td>
                                            <td><input type="number" style="width: 50px" data-order-id="{{ $order_model->id }}" value="{{ $order_model->amount }}"></td>
                                            <td class="total-price">{{ number_format(\App\Helpers\OrdersHelper::getTotalPrice($current_max_price, $order_model->amount), 2) }}</td>
                                            <td style="text-align: right"><button class="btn btn-xs btn-danger" onclick="destroyOrder({{ $order_model->id }});">удалить</button></td>
                                        </tr>
                                        @endforeach
                                        </tbody>
                                        <tfoot>
                                        <tr>
                                            <td></td>
                                            <td></td>
 /**
  * Добавление всех продуктов поставщика в закупку
  * @throws \Exception
  */
 public function postAddAllProducts()
 {
     $purchase_id = \Input::get('purchase_id');
     $purchase_model = $this->user->purchases()->find($purchase_id);
     \App\Helpers\Assistant::assertModel($purchase_model);
 }
 /**
  * Вычисляет текущую максимальную колонку и общую сумму заказов
  */
 protected function calculateCurrentMaxPricingGridColumnIdAndOrdersTotalSum()
 {
     $orders_total_sum_matrix = $this->getOrdersTotalSumMatrix();
     $pricing_grid_columns_models_arr = $this->getPricingGridColumns()->get();
     if (!$pricing_grid_columns_models_arr) {
         \App\Helpers\Assistant::exception("Не назначено ни одной ценовой колонки для закупки {$this->id}");
     }
     /**
      * @var $pricing_grid_column_model \App\Models\PricingGridColumnModel
      */
     foreach ($pricing_grid_columns_models_arr as $pricing_grid_column_model) {
         if ($pricing_grid_column_model->maxSumInclusive()) {
             if ($orders_total_sum_matrix[$pricing_grid_column_model->id] > $pricing_grid_column_model->maxSum()) {
                 continue;
             }
         } else {
             if ($orders_total_sum_matrix[$pricing_grid_column_model->id] >= $pricing_grid_column_model->maxSum()) {
                 continue;
             }
         }
         $this->current_max_pricing_grid_column_id = $pricing_grid_column_model->id;
         $this->orders_total_sum = $orders_total_sum_matrix[$pricing_grid_column_model->id];
         break;
     }
 }
Esempio n. 14
0
 /**
  * Изменение объема заказа
  * @param $order_id
  * @param $amount
  * @return \App\BusinessLogic\Models\Order|null
  */
 public function updateAmountOrder($order_id, $amount)
 {
     // TODO: сделать проверку прав на изменение заказа
     $order = $this->orders()->find($order_id);
     \App\Helpers\Assistant::assertModel($order);
     $order->updateAmount($amount);
     return $order;
 }