2021-11-07 开源测试版 2.4.0
This commit is contained in:
@@ -9,8 +9,6 @@ use Gdoo\Model\Form;
|
||||
use Gdoo\Model\Grid;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Produce\Models\Material;
|
||||
use Gdoo\Produce\Models\Formula;
|
||||
|
||||
use Gdoo\Produce\Services\ProduceService;
|
||||
|
||||
@@ -18,94 +16,7 @@ use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class MaterialController extends DefaultController
|
||||
{
|
||||
public $permission = ['dialog', 'config', 'configSave', 'planProduct', 'planTotal'];
|
||||
|
||||
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['left_buttons'] = [
|
||||
['name' => '配料', 'color' => 'default', 'icon' => 'fa-file-text-o', 'action' => 'config', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = Material::$tabs;
|
||||
|
||||
$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']);
|
||||
|
||||
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->render([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
public function edit()
|
||||
{
|
||||
return $this->create('edit');
|
||||
}
|
||||
|
||||
// 配方
|
||||
public function config()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
if (Request::method() == 'POST') {
|
||||
$rows = DB::table('product_formula')->where('material_id', $id)
|
||||
->leftJoin('product', 'product.id', '=', 'product_formula.product_id')
|
||||
->leftJoin('product_unit', 'product_unit.id', '=', 'product.unit_id')
|
||||
->get([
|
||||
'product.name as product_name',
|
||||
'product.code as product_code',
|
||||
'product.spec as product_spec',
|
||||
'product_unit.name as product_unit',
|
||||
'product_formula.*'
|
||||
]);
|
||||
return $this->json($rows, true);
|
||||
}
|
||||
return $this->display(['id' => $id]);
|
||||
}
|
||||
public $permission = ['planProduct', 'planTotal'];
|
||||
|
||||
// 用料计划
|
||||
public function plan()
|
||||
@@ -184,7 +95,7 @@ class MaterialController extends DefaultController
|
||||
c.name as product_unit,
|
||||
a.product_num,
|
||||
a.material_id,
|
||||
d.category as category_name,
|
||||
dc.name as category_name,
|
||||
d.name as material_name,
|
||||
a.material_num,
|
||||
a.total_num
|
||||
@@ -195,8 +106,9 @@ class MaterialController extends DefaultController
|
||||
from material_plan_day a
|
||||
left join product b on a.product_id = b.id
|
||||
left join product_unit AS c ON b.unit_id = c.id
|
||||
left join product_material d on a.Material_Id = d.Id
|
||||
where a.date = '".$date."' and a.Dept_Id = $department_id and a.Product_Id = $product_id";
|
||||
left join product d on a.material_id = d.id
|
||||
left join product_category dc on dc.id = d.category_id
|
||||
where a.date = '".$date."' and a.dept_id = $department_id and a.product_id = $product_id";
|
||||
$rows = DB::select($sql);
|
||||
}
|
||||
return $this->json($rows, true);
|
||||
@@ -222,16 +134,17 @@ class MaterialController extends DefaultController
|
||||
$sql = "select a.date,
|
||||
a.dept_id,
|
||||
a.material_id,
|
||||
d.category as category_name,
|
||||
dc.name as category_name,
|
||||
d.name as material_name,
|
||||
sum(a.material_num) material_num,
|
||||
sum(a.total_num)total_num
|
||||
sum(a.total_num) total_num
|
||||
from material_plan_day a
|
||||
left join product b on a.product_id = b.id
|
||||
left join product_unit AS c ON b.unit_id = c.id
|
||||
left join product_material d on a.Material_Id = d.Id
|
||||
where a.date = '$date' and a.Dept_Id = ".$department_id."
|
||||
group by a.Date, a.Dept_Id, a.Material_Id, d.category, d.Name";
|
||||
left join product d on a.material_id = d.id
|
||||
left join product_category dc on dc.id = d.category_id
|
||||
where a.date = '$date' and a.dept_id = ".$department_id."
|
||||
group by a.date, a.dept_id, a.material_id, dc.name, d.name";
|
||||
$rows = DB::select($sql);
|
||||
}
|
||||
return $this->json($rows, true);
|
||||
@@ -241,83 +154,4 @@ class MaterialController extends DefaultController
|
||||
'query' => $query,
|
||||
]);
|
||||
}
|
||||
|
||||
// 配方保存
|
||||
public function configSave()
|
||||
{
|
||||
$gets = Request::all();
|
||||
$id = $gets['id'];
|
||||
if (empty($id)) {
|
||||
return $this->json('原辅料编号不能为空');
|
||||
}
|
||||
|
||||
$data = $gets['product_formula'];
|
||||
|
||||
// 新增或者修改
|
||||
foreach((array)$data['rows'] as $_row) {
|
||||
$_row['material_id'] = $id;
|
||||
$row = Formula::findOrNew($_row['id']);
|
||||
$row->fill($_row)->save();
|
||||
}
|
||||
|
||||
// 删除记录
|
||||
foreach((array)$data['deleteds'] as $row) {
|
||||
if ($row['id'] > 0) {
|
||||
Formula::where('id', $row['id'])->delete();
|
||||
}
|
||||
}
|
||||
return $this->json('配方保存成功。', true);
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'product_material', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
|
||||
public function dialog()
|
||||
{
|
||||
$search = search_form([
|
||||
'advanced' => '',
|
||||
'prefix' => '',
|
||||
'offset' => '',
|
||||
'sort' => '',
|
||||
'order' => '',
|
||||
'limit' => '',
|
||||
], [
|
||||
['text','logistics.name','名称'],
|
||||
]);
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table('logistics');
|
||||
// 排序方式
|
||||
if ($query['sort'] && $query['order']) {
|
||||
$model->orderBy('logistics.'.$query['sort'], $query['order']);
|
||||
}
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
$model->selectRaw("logistics.*");
|
||||
|
||||
if ($query['limit']) {
|
||||
$rows = $model->paginate($query['limit']);
|
||||
} else {
|
||||
$rows['total'] = $model->count();
|
||||
$rows['data'] = $model->get();
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
return $this->render([
|
||||
'search' => $search,
|
||||
'query' => $query,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ use Gdoo\Model\Grid;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Produce\Models\Plan;
|
||||
use Gdoo\Produce\Models\Formula;
|
||||
|
||||
use Gdoo\Produce\Services\ProduceService;
|
||||
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php namespace Gdoo\Produce\Models;
|
||||
|
||||
use Gdoo\Index\Models\BaseModel;
|
||||
|
||||
class Formula extends BaseModel
|
||||
{
|
||||
protected $table = 'product_formula';
|
||||
|
||||
public static $tabs = [
|
||||
'name' => 'tab',
|
||||
'items' => [
|
||||
['value' => 'material.index', 'url' => 'produce/material/index', 'name' => '原辅料档案'],
|
||||
]
|
||||
];
|
||||
|
||||
public static $bys = [
|
||||
'name' => 'by',
|
||||
'items' => [
|
||||
['value' => '', 'name' => '全部'],
|
||||
['value' => 'divider'],
|
||||
['value' => 'day', 'name' => '今日创建'],
|
||||
['value' => 'week', 'name' => '本周创建'],
|
||||
['value' => 'month', 'name' => '本月创建'],
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
<?php namespace Gdoo\Produce\Models;
|
||||
|
||||
use Gdoo\Index\Models\BaseModel;
|
||||
|
||||
class Material extends BaseModel
|
||||
{
|
||||
protected $table = 'product_material';
|
||||
|
||||
public static $tabs = [
|
||||
'name' => 'tab',
|
||||
'items' => [
|
||||
['value' => 'material.index', 'url' => 'produce/material/index', 'name' => '原辅料档案'],
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -25,7 +25,7 @@ class ProduceService
|
||||
if ($date) {
|
||||
if ($isCalAgain) {
|
||||
// 删除先有计划
|
||||
DB::delete("delete FROM material_plan_day where date = '$date' and Dept_Id=$department_id");
|
||||
DB::delete("delete FROM material_plan_day where date = '$date' and dept_id = $department_id");
|
||||
|
||||
// 获取生产计划
|
||||
$items = DB::select("
|
||||
@@ -35,11 +35,11 @@ class ProduceService
|
||||
c.quantity as material_num,
|
||||
c.material_id,
|
||||
d.department_id,
|
||||
case when ISNULL(c.ratio, 1) = 0 then 0 else ISNULL(d.plan_num, 0) * ISNULL(c.quantity, 0) / ISNULL(c.ratio, 1) end as total_num
|
||||
ISNULL(d.plan_num, 0) * ISNULL(c.quantity, 0) + (ISNULL(c.quantity, 0) * ISNULL(c.loss_rate, 0)) AS total_num
|
||||
FROM produce_plan m, produce_plan_data d
|
||||
left join(
|
||||
select a.product_id, a.material_id, a.quantity, b.ratio
|
||||
from product_formula a left join product_material b on a.material_id = b.id
|
||||
select product_id, material_id, quantity, loss_rate
|
||||
from product_material
|
||||
) c on c.product_id = d.product_id
|
||||
WHERE m.id = d.plan_id
|
||||
AND isnull(department_id, 0) = $department_id
|
||||
@@ -47,7 +47,7 @@ class ProduceService
|
||||
AND plan_num IS NOT NULL
|
||||
AND m.date = '$date'
|
||||
");
|
||||
|
||||
|
||||
foreach($items as $item) {
|
||||
DB::table("material_plan_day")->insert([
|
||||
'date' => $date,
|
||||
@@ -76,7 +76,7 @@ class ProduceService
|
||||
c.name as product_unit,
|
||||
a.product_num,
|
||||
a.material_id,
|
||||
d.category as category_name,
|
||||
dc.name as category_name,
|
||||
d.name as material_name,
|
||||
a.material_num,
|
||||
a.total_num,
|
||||
@@ -87,9 +87,10 @@ class ProduceService
|
||||
from material_plan_day a
|
||||
left join product b on a.product_id = b.id
|
||||
left join product_unit AS c ON b.unit_id = c.id
|
||||
left join product_material d on a.Material_Id = d.id
|
||||
left join department e on a.Dept_Id = e.id
|
||||
where a.date = '$date' and a.Dept_Id = $department_id
|
||||
left join product d on a.material_id = d.id
|
||||
left join product_category dc on dc.id = d.category_id
|
||||
left join department e on a.dept_id = e.id
|
||||
where a.date = '$date' and a.dept_Id = $department_id
|
||||
");
|
||||
}
|
||||
return $rows;
|
||||
@@ -1021,21 +1022,21 @@ class ProduceService
|
||||
}
|
||||
|
||||
$sql2[] = "select p.id,
|
||||
pc.id as category_id,
|
||||
pc.code as category_code,
|
||||
pc.name as category_name,
|
||||
pc.id as category_id,
|
||||
pc.code as category_code,
|
||||
pc.name as category_name,
|
||||
p.id as product_id,
|
||||
p.code as product_code,
|
||||
p.name as product_name,
|
||||
p.spec as product_spec,
|
||||
Concat(p.name,' ', isnull(p.spec,'')) as product_name_spec,
|
||||
p.code as product_code,
|
||||
p.name as product_name,
|
||||
p.spec as product_spec,
|
||||
Concat(p.name,' ', isnull(p.spec,'')) as product_name_spec,
|
||||
isnull(batch_sn,'') as batch_sn,
|
||||
pu.name as product_unit,
|
||||
sum(wf_num) dphz_num,
|
||||
sum(wf_num_ydk) ydk_num,
|
||||
sum(wf_num_wdk) wdk_num,
|
||||
sum(kc_num) kc_num,
|
||||
ISNULL(sum(wf_num), 0) - ISNULL(sum(kc_num), 0) as xqzc_num,
|
||||
ISNULL(sum(wf_num), 0) - ISNULL(sum(kc_num), 0) as xqzc_num,
|
||||
ISNULL(sum(wf_num_ydk) ,0) as yhk_num,
|
||||
ISNULL(sum(wf_num_ydk), 0) - ISNULL(sum(kc_num), 0) as kfzc_num,
|
||||
ISNULL(sum(wfhjh_num), 0) - ISNULL(sum(kc_num), 0) as kfjh_num,
|
||||
@@ -1057,8 +1058,7 @@ class ProduceService
|
||||
$sql2[] = "and p.is_export = 1";
|
||||
}
|
||||
|
||||
$sql2[] = "group by pc.id,pc.name,pc.code,p.id,p.code,p.name,isnull(batch_sn,''),p.spec,pu.name
|
||||
order by p.code";
|
||||
$sql2[] = "group by pc.id,pc.name,pc.code,p.id,p.code,p.name,isnull(batch_sn,''),p.spec,pu.name order by p.code";
|
||||
$rows = DB::select(join(' ', $sql2));
|
||||
return $rows;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user