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]);
 }
예제 #2
0
 /**
  * @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 setPricingGridColumns($beginning_column_id, $final_column_id = null)
 {
     $pricing_grid_columns_ids_arr = [];
     /**
      * @var $beginning_column_model \App\Models\PricingGridColumnModel
      */
     $beginning_column_model = \App\Models\PricingGridColumnModel::find($beginning_column_id);
     \App\Helpers\Assistant::assertModel($beginning_column_model, 'Не найдено модели PricingGridColumnModel с идентификатором ID#' . $beginning_column_id);
     $pricing_grid_model = $beginning_column_model->pricing_grid();
     \App\Helpers\Assistant::assertModel($pricing_grid_model, 'Не найдено связанной модели PricingGridModel с моделью PricingGridColumnModel ID#' . $beginning_column_id);
     $pricing_grid_columns_ids_arr[] = $beginning_column_model->id;
     $final_column_id = intval($final_column_id);
     if ($final_column_id) {
         $pricing_grid_columns_models = $pricing_grid_model->columns();
         \App\Helpers\Assistant::assertNotEmpty($pricing_grid_columns_models, 'Модель PricingGridModel ID#' . $pricing_grid_model->id . ' не имеет ценовых колонок');
         foreach ($pricing_grid_columns_models as $pricing_grid_column_model) {
             $pricing_grid_columns_ids_arr[] = $pricing_grid_column_model->id;
             if ($pricing_grid_column_model->id = $final_column_id) {
                 break;
             }
         }
         \App\Helpers\Assistant::assert(in_array($final_column_id, $pricing_grid_columns_ids_arr));
     }
     $this->pricing_grid_columns()->attach($pricing_grid_columns_ids_arr);
     return true;
 }
 /**
  * Разблокирование блокирующей транзакции
  * @throws \Exception
  */
 public function unblocking()
 {
     if ($this->operation_type !== self::OPERATION_TYPE_BLOCKING) {
         return false;
     }
     $order = $this->order;
     \App\Helpers\Assistant::assertModel($order);
     // Начало транзакции БД
     \DB::beginTransaction();
     self::create(['sum' => $this->sum, 'user_id' => $order->user->id, 'operation_type' => self::OPERATION_TYPE_UNBLOCKING, 'operation_type_code' => self::OPERATION_TYPE_UNBLOCKING_CODE, 'order_id' => $order->id]);
     \App\ActionLog::action('PAYMENT_TRANSACTION.UNBLOCKING', ['payment_transaction_id' => $this->id, 'sum' => $this->sum, 'user_id' => $order->user->id, 'operation_type' => self::OPERATION_TYPE_UNBLOCKING, 'operation_type_code' => self::OPERATION_TYPE_UNBLOCKING_CODE, 'order_id' => $order->id]);
     \DB::commit();
     // Окончание транзакции БД
     return true;
 }
 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]);
 }
예제 #6
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);
 }
예제 #7
0
$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>
예제 #8
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;
 }
예제 #9
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);
 }
예제 #11
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;
 }