创建版本
This commit is contained in:
@@ -0,0 +1,222 @@
|
||||
<?php namespace Gdoo\Produce\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Auth;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Form;
|
||||
use Gdoo\Model\Grid;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Produce\Models\Plan;
|
||||
use Gdoo\Produce\Models\Formula;
|
||||
|
||||
use Gdoo\Produce\Services\ProduceService;
|
||||
|
||||
use Gdoo\Index\Controllers\WorkflowController;
|
||||
|
||||
class PlanController extends WorkflowController
|
||||
{
|
||||
public $permission = ['dialog', 'orderPlan', 'planExport'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'produce_plan',
|
||||
'referer' => 1,
|
||||
'search' => ['by' => ''],
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '编辑',
|
||||
'action' => 'edit',
|
||||
'display' => $this->access['edit'],
|
||||
]];
|
||||
|
||||
$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);
|
||||
$items = Grid::dataFilters($rows, $header);
|
||||
return $items->toJson();
|
||||
}
|
||||
|
||||
$header['buttons'] = [
|
||||
//['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
|
||||
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = Plan::$tabs;
|
||||
$header['bys'] = Plan::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 生产计划导出
|
||||
public function planExportAction()
|
||||
{
|
||||
$search = search_form([
|
||||
'advanced' => 0,
|
||||
], [
|
||||
['form_type' => 'date', 'name' => '计划时间', 'field' => 'date', 'options' => []
|
||||
],
|
||||
], 'model');
|
||||
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$date = $query['search_0'];
|
||||
$rows = [];
|
||||
if ($date) {
|
||||
|
||||
$departments = DB::table('produce_plan_data')
|
||||
->leftJoin('produce_plan', 'produce_plan.id', '=', 'produce_plan_data.plan_id')
|
||||
->leftJoin('department', 'department.id', '=', 'produce_plan_data.department_id')
|
||||
->where('produce_plan.date', $date)
|
||||
->where('department.id', '>', 0)
|
||||
->groupBy('department.id', 'department.name')
|
||||
->get(['department.id','department.name']);
|
||||
|
||||
foreach($departments as $index => $department) {
|
||||
$sql = "
|
||||
SELECT p.name as product_name, p.spec as product_spec, pu.name as product_unit, d.plan_num, d.remark, d.batch_sn, m.date
|
||||
FROM produce_plan_data d
|
||||
left join produce_plan m on m.id = d.plan_id
|
||||
left join product p on d.product_id = p.id
|
||||
left join product_unit pu on pu.id = p.unit_id
|
||||
WHERE m.id = d.plan_id
|
||||
AND isnull(d.department_id, 0) = ?
|
||||
AND d.plan_num <> 0
|
||||
AND d.plan_num IS NOT NULL
|
||||
AND m.date = ? AND m.type = 1";
|
||||
$items = DB::select($sql, [$department['id'], $date]);
|
||||
|
||||
if ($index > 0) {
|
||||
$rows[] = [];
|
||||
}
|
||||
|
||||
$rows[] = [
|
||||
'product_name' => '序号:'.($index + 1),
|
||||
'product_spec' => '',
|
||||
'product_unit' => '生产车间',
|
||||
'plan_num' => $department['name'],
|
||||
'quantity' => '',
|
||||
'remark' => '',
|
||||
'date' => ''
|
||||
];
|
||||
|
||||
$rows[] = [
|
||||
'product_name' => '成品品种',
|
||||
'product_spec' => '规格',
|
||||
'product_unit' => '单位',
|
||||
'plan_num' => '计划数量',
|
||||
'quantity' => '生产数量',
|
||||
'remark' => '备注',
|
||||
'date' => '计划日期'
|
||||
];
|
||||
|
||||
$plan_num = 0;
|
||||
foreach($items as $item) {
|
||||
$plan_num += $item['plan_num'];
|
||||
$rows[] = [
|
||||
'product_name' => $item['product_name'],
|
||||
'product_spec' => $item['product_spec'],
|
||||
'product_unit' => $item['product_unit'],
|
||||
'plan_num' => $item['plan_num'],
|
||||
'remark' => $item['batch_sn'],
|
||||
'date' => $item['date'],
|
||||
];
|
||||
}
|
||||
$rows[] = [
|
||||
'product_name' => '总量',
|
||||
'product_spec' => '',
|
||||
'product_unit' => '',
|
||||
'plan_num' => $plan_num,
|
||||
'remark' => '',
|
||||
'date' => ''
|
||||
];
|
||||
}
|
||||
}
|
||||
return $this->json($rows, true);
|
||||
}
|
||||
$search['table'] = 'material_plan';
|
||||
return $this->display([
|
||||
'search' => $search,
|
||||
'query' => $query,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建
|
||||
public function createAction($action = 'edit')
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$form = Form::make(['code' => 'produce_plan', 'id' => $id, 'action' => $action]);
|
||||
return $this->display([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 审核
|
||||
public function auditAction()
|
||||
{
|
||||
return $this->createAction('edit');
|
||||
}
|
||||
|
||||
// 创建
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction('edit');
|
||||
}
|
||||
|
||||
// 创建
|
||||
public function showAction()
|
||||
{
|
||||
return $this->createAction('show');
|
||||
}
|
||||
|
||||
// 参照订单计划
|
||||
public function orderPlanAction()
|
||||
{
|
||||
$plan_date = Request::get('plan_date');
|
||||
$rows = [];
|
||||
if ($plan_date) {
|
||||
$rows = ProduceService::getProducePlanQuantity($plan_date);
|
||||
if (empty($rows)) {
|
||||
return $this->json($plan_date.'无营销计划和外贸订单。');
|
||||
} else {
|
||||
return $this->json($rows, true);
|
||||
}
|
||||
}
|
||||
return $this->json($rows, true);
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'produce_plan', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user