2021-11-07 开源测试版 2.4.0
This commit is contained in:
@@ -0,0 +1,176 @@
|
||||
<?php namespace Gdoo\Product\Controllers;
|
||||
|
||||
use DB;
|
||||
use Input;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Product\Models\ProductMaterial;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class MaterialController extends DefaultController
|
||||
{
|
||||
public $permission = ['dialog', 'list', 'getMaterials'];
|
||||
|
||||
public function index()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'product_material',
|
||||
'referer' => 1,
|
||||
'search' => ['by' => ''],
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '编辑',
|
||||
'action' => 'edit',
|
||||
'display' => $this->access['edit'],
|
||||
]];
|
||||
|
||||
$header['buttons'] = [
|
||||
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
|
||||
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['right_buttons'] = [
|
||||
['name' => '导入', 'icon' => 'fa-mail-reply', 'color' => 'default', 'action' => 'import', 'display' => $this->access['import']],
|
||||
];
|
||||
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = ProductMaterial::$tabs;
|
||||
$header['bys'] = ProductMaterial::$bys;
|
||||
|
||||
$search = $header['search_form'];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table($header['table'])->setBy($header);
|
||||
foreach ($header['join'] as $join) {
|
||||
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
|
||||
}
|
||||
$model->orderBy($header['sort'], $header['order']);
|
||||
$model->where('product_id_product.id', '>', 0);
|
||||
$model->where('product_id_product.status', 1);
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
$model->select($header['select']);
|
||||
$rows = $model->paginate($query['limit'])->appends($query);
|
||||
return Grid::dataFilters($rows, $header);
|
||||
}
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
public function create($action = 'edit')
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$form = Form::make(['code' => 'product_material', 'id' => $id, 'action' => $action]);
|
||||
|
||||
return $this->display([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
public function edit()
|
||||
{
|
||||
return $this->create();
|
||||
}
|
||||
|
||||
public function show()
|
||||
{
|
||||
return $this->create('edit');
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
$gets = Request::all();
|
||||
if ($gets['product_id']) {
|
||||
$header = Grid::header([
|
||||
'code' => 'product_material',
|
||||
]);
|
||||
$model = ProductMaterial::where('product_id', $gets['product_id']);
|
||||
foreach ($header['join'] as $join) {
|
||||
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
|
||||
}
|
||||
|
||||
$model->leftJoin('product_unit as material_unit', 'material_unit.id', '=', 'material_id_product.unit_id');
|
||||
|
||||
$model->where('product_id_product.status', 1);
|
||||
$model->orderBy('product_material.id', 'asc');
|
||||
|
||||
$header['select'][] = 'material_id_product.code as material_code';
|
||||
$header['select'][] = 'material_id_product.spec as material_spec';
|
||||
$header['select'][] = 'material_id_product.barcode as material_barcode';
|
||||
$header['select'][] = 'material_unit.name as material_unit';
|
||||
|
||||
$rows = $model->get($header['select']);
|
||||
$rows = Grid::dataFilters($rows, $header, function($row) {
|
||||
$row['material_name'] = $row['material_id_name'];
|
||||
$row['warehouse_name'] = $row['warehouse_id_name'];
|
||||
return $row;
|
||||
});
|
||||
} else {
|
||||
$rows = ['data' =>[], 'header' => []];
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public function getMaterials()
|
||||
{
|
||||
$gets = Request::all();
|
||||
if ($gets['product_id']) {
|
||||
$rows = ProductMaterial::leftJoin('product', 'product.id', '=', 'product_material.material_id')
|
||||
->leftJoin('product_unit', 'product_unit.id', '=', 'product.unit_id')
|
||||
->leftJoin('warehouse', 'warehouse.id', '=', 'product.warehouse_id')
|
||||
->where('product_material.product_id', $gets['product_id'])
|
||||
->selectRaw('
|
||||
product_material.quantity,
|
||||
product_material.quantity base_quantity,
|
||||
product_material.loss_rate,
|
||||
product.warehouse_id,
|
||||
warehouse.name warehouse_id_name,
|
||||
product_material.material_id product_id,
|
||||
product.spec product_code,
|
||||
product.name product_name,
|
||||
product.spec product_spec,
|
||||
product.barcode product_barcode,
|
||||
product.purchase_price price,
|
||||
product_unit.name product_unit
|
||||
')
|
||||
->get();
|
||||
|
||||
return $this->json($rows, true);
|
||||
}
|
||||
}
|
||||
|
||||
public function import()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
return Form::import(['table' => 'product_material', 'keys' => ['product_id', 'material_id']]);
|
||||
}
|
||||
$tips = '注意:表格里必须包含[存货编码,物料编码]列。';
|
||||
return $this->render(['tips' => $tips], 'layouts.import');
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'product_material', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php namespace Gdoo\Product\Hooks;
|
||||
|
||||
use DB;
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Product\Models\ProductMaterial;
|
||||
|
||||
class MaterialHook
|
||||
{
|
||||
public function onBeforeForm($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onAfterForm($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onBeforeStore($params)
|
||||
{
|
||||
$gets = $params['gets'];
|
||||
$material = $gets['product_material'];
|
||||
$material_data = $gets['product_material_data'];
|
||||
|
||||
$id = 0;
|
||||
|
||||
// 新增或者修改
|
||||
foreach((array)$material_data['rows'] as $row) {
|
||||
$row['product_id'] = $material['product_id'];
|
||||
$_bom = ProductMaterial::findOrNew($row['id']);
|
||||
$_bom->fill($row)->save();
|
||||
$id = $_bom->id;
|
||||
}
|
||||
|
||||
// 删除记录
|
||||
foreach((array)$material_data['deleteds'] as $row) {
|
||||
if ($row['id'] > 0) {
|
||||
ProductMaterial::where('id', $row['id'])->delete();
|
||||
}
|
||||
}
|
||||
|
||||
$master['id'] = $id;
|
||||
$params['master'] = $master;
|
||||
|
||||
// 终止执行的进程后
|
||||
$params['terminate'] = false;
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onAfterStore($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onBeforeDelete($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,4 +39,9 @@ class Product extends BaseModel
|
||||
{
|
||||
return $this->belongsTo('Gdoo\Product\Models\Warehouse');
|
||||
}
|
||||
|
||||
public function scopeDialog($q, $value)
|
||||
{
|
||||
return $q->whereIn('id', $value)->pluck('name', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php namespace Gdoo\Product\Models;
|
||||
|
||||
use Gdoo\Index\Models\BaseModel;
|
||||
|
||||
class ProductMaterial extends BaseModel
|
||||
{
|
||||
protected $table = 'product_material';
|
||||
|
||||
public static $tabs = [
|
||||
'name' => 'tab',
|
||||
'items' => [
|
||||
['value' => 'material.index', 'url' => 'product/material/index', 'name' => '物料清单'],
|
||||
]
|
||||
];
|
||||
|
||||
public static $bys = [
|
||||
'name' => 'by',
|
||||
'items' => [
|
||||
['value' => '', 'name' => '全部'],
|
||||
['value' => 'enabled', 'name' => '启用'],
|
||||
['value' => 'disabled', 'name' => '禁用'],
|
||||
['value' => 'divider'],
|
||||
['value' => 'day', 'name' => '今日创建'],
|
||||
['value' => 'week', 'name' => '本周创建'],
|
||||
['value' => 'month', 'name' => '本月创建'],
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -5,6 +5,7 @@ return [
|
||||
"description" => "产品列表,产品类别,库存类型,仓库类别,库存管理,仓库列表。",
|
||||
"listens" => [
|
||||
'product_category' => 'Gdoo\Product\Hooks\CategoryHook',
|
||||
'product_material' => 'Gdoo\Product\Hooks\MaterialHook',
|
||||
],
|
||||
'dialogs' => [
|
||||
'product' => [
|
||||
@@ -62,7 +63,7 @@ return [
|
||||
]
|
||||
],
|
||||
"material" => [
|
||||
"name" => "原材料清单",
|
||||
"name" => "物料清单",
|
||||
"actions" => [
|
||||
"index" => [
|
||||
"name" => "列表"
|
||||
@@ -73,9 +74,15 @@ return [
|
||||
"edit" => [
|
||||
"name" => "编辑"
|
||||
],
|
||||
"show" => [
|
||||
"name" => "显示"
|
||||
],
|
||||
"import" => [
|
||||
"name" => "导入"
|
||||
],
|
||||
"delete" => [
|
||||
"name" => "删除"
|
||||
],
|
||||
]
|
||||
]
|
||||
],
|
||||
"category" => [
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
<div class="form-panel">
|
||||
<div class="form-panel-header">
|
||||
<div class="pull-right">
|
||||
</div>
|
||||
{{$form['btn']}}
|
||||
</div>
|
||||
<div class="form-panel-body panel-form-{{$form['action']}}">
|
||||
<form class="form-horizontal form-controller" method="post" id="{{$form['table']}}" name="{{$form['table']}}">
|
||||
<div class="panel">
|
||||
{{$form['tpl']}}
|
||||
</div>
|
||||
<div id="tab-content-product_material">
|
||||
<div id="grid_product_material_data" class="ag-theme-balham ag-bordered" style="width:100%;"></div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var $table = null;
|
||||
var product_id = $('#product_material_product_id').val();
|
||||
var params = {product_id: product_id};
|
||||
|
||||
(function($) {
|
||||
var options = {};
|
||||
options.columns = [
|
||||
{field:'id', hide: true},
|
||||
{field:'material_id', hide: true},
|
||||
{field:'warehouse_id', hide: true},
|
||||
{suppressSizeToFit: true, headerName:'', cellRenderer:'optionCellRenderer', width: 60, sortable: false, cellClass: 'text-center', suppressNavigable: true},
|
||||
{headerName: '仓库',editable: true, cellClass:'text-center', suppressNavigable: false, width: 100,
|
||||
cellEditorParams: {
|
||||
form_type: 'dialog',
|
||||
title: '仓库',
|
||||
type: 'warehouse',
|
||||
field: 'warehouse_name',
|
||||
url: 'stock/warehouse/dialog',
|
||||
query: {
|
||||
form_id: "product_material_data",
|
||||
id: "warehouse_id",
|
||||
name: "warehouse_name"
|
||||
}
|
||||
},
|
||||
cellEditor: 'dialogCellEditor',
|
||||
field: 'warehouse_name'
|
||||
},
|
||||
{headerName: '物料编码', field:'material_code', cellClass:'text-center', suppressNavigable: false, width: 120},
|
||||
{headerName: '物料名称',editable: true,suppressNavigable: false, width: 220,
|
||||
cellEditorParams: {
|
||||
form_type: 'dialog',
|
||||
title: '物料',
|
||||
type: 'product',
|
||||
field: 'material_name',
|
||||
url: 'product/product/dialog',
|
||||
query: {
|
||||
form_id: "product_material_data",
|
||||
id: "material_id",
|
||||
name: "material_name"
|
||||
}
|
||||
},
|
||||
cellEditor: 'dialogCellEditor',
|
||||
field: 'material_name'
|
||||
},
|
||||
{headerName: '规格型号', field:'material_spec', cellClass:'text-center', suppressNavigable: false, width: 160},
|
||||
{headerName: '物料条码', field:'material_barcode', cellClass:'text-center', suppressNavigable: false, width: 120},
|
||||
{headerName: '计量单位', field:'material_unit', cellClass:'text-center', suppressNavigable: false, width: 100},
|
||||
{headerName: '用量', field:'quantity', editable: true, cellClass:'text-right', width: 100},
|
||||
{headerName: '损耗率(%)', field:'loss_rate', type:'number', editable: true, cellClass:'text-center', width: 100},
|
||||
{headerName: '备注', field:'remark', editable: true, width: 200},
|
||||
];
|
||||
|
||||
options.table = "product_material_data";
|
||||
options.title = "物料列表";
|
||||
options.heightTop = 12;
|
||||
|
||||
options.links = {
|
||||
warehouse_id: {
|
||||
warehouse_id: "id",
|
||||
warehouse_name: "name",
|
||||
},
|
||||
material_id: {
|
||||
material_id: "id",
|
||||
material_name: "name",
|
||||
material_code: "code",
|
||||
material_spec: "spec",
|
||||
material_barcode: "barcode",
|
||||
material_unit: "unit_id_name"
|
||||
}
|
||||
};
|
||||
|
||||
var grid = gridForms("product_material", "product_material_data", options);
|
||||
grid.dataKey = 'material_id';
|
||||
|
||||
$.post(app.url('product/material/list'), params, function(res) {
|
||||
if (res.data.length > 0) {
|
||||
grid.api.setRowData(res.data);
|
||||
}
|
||||
});
|
||||
|
||||
// 选择产品事件
|
||||
gdoo.event.set('product_material.product_id', {
|
||||
onSelect(row) {
|
||||
if (row.id) {
|
||||
params['product_id'] = row.id;
|
||||
$.post(app.url('product/material/list'), params, function(res) {
|
||||
if (res.data.length > 0) {
|
||||
grid.api.setRowData(res.data);
|
||||
} else {
|
||||
grid.api.setRowData([]);
|
||||
grid.api.memoryStore.create({});
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
</script>
|
||||
@@ -0,0 +1,46 @@
|
||||
<div class="gdoo-list-page" id="{{$header['master_table']}}-page">
|
||||
<div class="gdoo-list panel">
|
||||
<div class="gdoo-list-header">
|
||||
<gdoo-grid-header :header="header" :grid="grid" :action="action" />
|
||||
</div>
|
||||
<div class='gdoo-list-grid'>
|
||||
<div id="{{$header['master_table']}}-grid" class="ag-theme-balham"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
Vue.createApp({
|
||||
components: {
|
||||
gdooGridHeader,
|
||||
},
|
||||
setup(props, ctx) {
|
||||
var table = '{{$header["master_table"]}}';
|
||||
|
||||
var config = new gdoo.grid(table);
|
||||
|
||||
var grid = config.grid;
|
||||
grid.autoColumnsToFit = true;
|
||||
grid.remoteDataUrl = '{{url()}}';
|
||||
|
||||
var action = config.action;
|
||||
|
||||
// 详情页打开方式
|
||||
action.dialogType = 'layer';
|
||||
|
||||
// 双击行执行的方法
|
||||
action.rowDoubleClick = action.edit;
|
||||
|
||||
var setup = config.setup;
|
||||
|
||||
Vue.onMounted(function() {
|
||||
var gridDiv = config.div(136);
|
||||
// 初始化数据
|
||||
grid.remoteData({page: 1}, function(res) {
|
||||
config.init(res);
|
||||
});
|
||||
});
|
||||
return setup;
|
||||
}
|
||||
}).mount("#{{$header['master_table']}}-page");
|
||||
</script>
|
||||
Reference in New Issue
Block a user