6
0
Fork 0
jiqu-library-server/app/Admin/Controllers/Store/StockTotalController.php

72 lines
3.3 KiB
PHP

<?php
namespace App\Admin\Controllers\Store;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Grid;
use App\Models\Store\{Store, StockLog};
use App\Models\{ProductCategory};
use App\Admin\Repositories\StoreTockRepository;
class StockTotalController extends AdminController
{
protected $translation = 'store-stock-total';
protected function grid()
{
// return Grid::make(ProductSku::with(['productSku.category', 'stockLogs']), function (Grid $grid) {
$request = request();
if (!$request->filled('date.start')) {
$request->offsetSet('date.start', now()->startOfMonth()->format('Y-m-d'));
}
if (!$request->filled('date.end')) {
$request->offsetSet('date.end', now()->format('Y-m-d'));
}
return Grid::make(new StoreTockRepository, function (Grid $grid) {
$tags = StockLog::tags()->get();
$grid->column('store_name', '门店');
$grid->column('name', '产品');
$grid->column('category_name', '分类');
$grid->column('cost_price', '成本单价');
$grid->column('sell_price', '售价');
$grid->column('init_stock', '初期库存');
$grid->column('tag_in', '入库数');
$grid->column('tag_sell', '销售数');
$grid->column('tag_online', '线上销售数');
$grid->column('tag_loss', '报损数');
$grid->column('tag_self', '自用数');
$grid->column('tag_out', '调货数');
$grid->column('stock', '现有库存')->sortable();
$grid->column('total_profit', '商品总毛利');
$grid->disableActions();
$grid->filter(function (Grid\Filter $filter) use ($tags) {
$filter->panel();
$filter->equal('store_id', '门店')->select(Store::pluck('title', 'id'))->width(3);
$filter->equal('category_id', '分类')->select(ProductCategory::selectOptions())->width(3);
$filter->equal('product_name', '商品')->width(3);
$filter->between('date', '时间')->date()->width(6);
});
$grid->footer(function ($collection) use ($grid) {
$total = $grid->model()->repository()->getTotal($grid->model());
$html = '<table class="table table-bordered"><tbody><tr>';
$html .= '<td>入库总成本: '.data_get($total, 'total_in').'</td>';
$html .= '<td>销售总金额: '.data_get($total, 'total_sell').'</td>';
$html .= '<td>线上销售总金额: '.data_get($total, 'total_online').'</td>';
$html .= '<td>报损总成本: '.data_get($total, 'total_loss').'</td>';
$html .= '<td>自用总成本: '.data_get($total, 'total_self').'</td>';
$html .= '<td>调货总金额: '.data_get($total, 'total_out').'</td>';
$html .= '<td>现有总成本: '.data_get($total, 'total_cost_price').'</td>';
$html .= '<td>现有总价值: '.data_get($total, 'total_sell_price').'</td>';
$html .= '<td>产品毛利汇总: '.data_get($total, 'total_profit').'</td>';
$html .= '</tr></tbody></table>';
return $html;
});
});
}
}