创建版本
This commit is contained in:
@@ -0,0 +1,220 @@
|
||||
<?php namespace Gdoo\Stock\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Stock\Models\Allocation;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Stock\Services\StockService;
|
||||
|
||||
use Gdoo\Index\Controllers\WorkflowController;
|
||||
|
||||
class AllocationController extends WorkflowController
|
||||
{
|
||||
public $permission = ['dialog', 'logistics', 'stockSelect'];
|
||||
|
||||
// 列表
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'stock_allocation',
|
||||
'referer' => 1,
|
||||
'search' => ['by' => ''],
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '显示',
|
||||
'action' => 'show',
|
||||
'display' => $this->access['show'],
|
||||
]];
|
||||
|
||||
$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'] = Allocation::$tabs;
|
||||
$header['bys'] = Allocation::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建
|
||||
public function createAction($action = 'edit')
|
||||
{
|
||||
$id = (int) Request::get('id');
|
||||
$header['action'] = $action;
|
||||
$header['code'] = 'stock_allocation';
|
||||
$header['id'] = $id;
|
||||
|
||||
$form = Form::make($header);
|
||||
$tpl = $action == 'print' ? 'print' : 'create';
|
||||
return $this->display([
|
||||
'form' => $form,
|
||||
], $tpl);
|
||||
}
|
||||
|
||||
// 编辑
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
// 审核
|
||||
public function auditAction()
|
||||
{
|
||||
return $this->createAction('audit');
|
||||
}
|
||||
|
||||
// 显示
|
||||
public function showAction()
|
||||
{
|
||||
return $this->createAction('show');
|
||||
}
|
||||
|
||||
// 打印
|
||||
public function printAction()
|
||||
{
|
||||
$id = Request::get('id');
|
||||
$template_id = Request::get('template_id');
|
||||
|
||||
$this->layout = 'layouts.print3';
|
||||
$master = DB::table('stock_allocation as m')
|
||||
->where('m.id', $id)
|
||||
->leftJoin('warehouse as wo', 'wo.id', '=', 'm.out_warehouse_id')
|
||||
->leftJoin('warehouse as wi', 'wi.id', '=', 'm.in_warehouse_id')
|
||||
->selectRaw('m.*, wi.name as in_warehouse_name, wo.name as out_warehouse_name, wi.code as in_warehouse_code, wo.code as out_warehouse_code')
|
||||
->first();
|
||||
|
||||
$rows = DB::table('stock_allocation_data as d')
|
||||
->leftJoin('stock_allocation as m', 'm.id', '=', 'd.allocation_id')
|
||||
->leftJoin('product as p', 'p.id', '=', 'd.product_id')
|
||||
->leftJoin('product_unit as pu', 'pu.id', '=', 'p.unit_id')
|
||||
->where('m.id', $id)
|
||||
->selectRaw('
|
||||
d.*,
|
||||
p.name as product_name,
|
||||
p.code as product_code,
|
||||
p.spec as product_spec,
|
||||
pu.name as product_unit
|
||||
')
|
||||
->orderBy('p.code', 'asc')
|
||||
->get();
|
||||
|
||||
$form = [
|
||||
'template' => DB::table('model_template')->where('id', $template_id)->first()
|
||||
];
|
||||
|
||||
if ($master['in_warehouse_code'] == 27 || $master['in_warehouse_code'] == 21) {
|
||||
$warehouse_by = '李志全';
|
||||
} else {
|
||||
$warehouse_by = '万海英';
|
||||
}
|
||||
|
||||
$tpl = $this->display([
|
||||
'master' => $master,
|
||||
'rows' => $rows,
|
||||
'form' => $form,
|
||||
'warehouse_by' => $warehouse_by,
|
||||
], 'print/'.$template_id);
|
||||
return $tpl;
|
||||
}
|
||||
|
||||
// 选择库存
|
||||
public function stockSelectAction()
|
||||
{
|
||||
$search = search_form(['advanced' => ''], [
|
||||
['form_type' => 'text', 'name' => '产品名称', 'field' => 'name'],
|
||||
['form_type' => 'text', 'name' => '产品编码', 'field' => 'code']
|
||||
], 'model');
|
||||
$query = $search['query'];
|
||||
if (Request::method() == 'POST') {
|
||||
$fields = [];
|
||||
foreach($search['forms']['field'] as $i => $field) {
|
||||
$fields[$field] = $search['forms']['search'][$i];
|
||||
}
|
||||
if($fields['name']) {
|
||||
$query['value'] = $fields['name'];
|
||||
}
|
||||
if($fields['code']) {
|
||||
$query['value'] = $fields['code'];
|
||||
}
|
||||
|
||||
$rows = StockService::getBatchSelectZY($query['warehouse_id'], '', $query['value']);
|
||||
return ['data' => $rows];
|
||||
}
|
||||
return $this->render([
|
||||
'search' => $search,
|
||||
]);
|
||||
}
|
||||
|
||||
// 物流信息
|
||||
public function logisticsAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$gets = Request::get('stock_allocation');
|
||||
$id = $gets['id'];
|
||||
$gets['freight_created_dt'] = date('Y-m-d H:i:s');
|
||||
$gets['freight_created_by'] = auth()->user()->name;
|
||||
DB::table('stock_allocation')->where('id', $id)->update($gets);
|
||||
return $this->json('物流信息提交成功。', true);
|
||||
}
|
||||
$file = base_path().'/addons/'.ucfirst(Request::module()).'/views/'.Request::controller().'/'.Request::action().'.html';
|
||||
$id = Request::get('id');
|
||||
$row = Allocation::find($id);
|
||||
$freight_quantity = floatval($row['freight_quantity']);
|
||||
|
||||
if ($freight_quantity == 0) {
|
||||
$count = DB::table('stock_allocation_data')
|
||||
->where('allocation_id', $id)->selectRaw('sum(total_weight) as weight, sum(quantity) as quantity')->first();
|
||||
$weight = number_format($count['weight'] / 1000, 2);
|
||||
$quantity = number_format($count['quantity'], 2);
|
||||
$row['freight_quantity'] = $quantity;
|
||||
$row['freight_weight'] = $weight;
|
||||
}
|
||||
$form = Form::make1(['table' => 'stock_allocation', 'file' => $file, 'row' => $row]);
|
||||
return $form;
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'stock_allocation', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
<?php namespace Gdoo\Stock\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Stock\Models\Cancel;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Index\Controllers\WorkflowController;
|
||||
|
||||
class CancelController extends WorkflowController
|
||||
{
|
||||
public $permission = ['dialog'];
|
||||
|
||||
// 列表
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'stock_cancel',
|
||||
'referer' => 1,
|
||||
'search' => ['by' => ''],
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '显示',
|
||||
'action' => 'show',
|
||||
'display' => $this->access['show'],
|
||||
]];
|
||||
|
||||
$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['left_buttons'] = [
|
||||
['name' => '批量编辑', 'color' => 'default', 'icon' => 'fa-pencil-square-o', 'action' => 'batchEdit', 'display' => $this->access['batchEdit']],
|
||||
];
|
||||
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = Cancel::$tabs;
|
||||
$header['bys'] = Cancel::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建
|
||||
public function createAction($action = 'edit')
|
||||
{
|
||||
$id = (int) Request::get('id');
|
||||
$header['action'] = $action;
|
||||
$header['code'] = 'stock_cancel';
|
||||
$header['id'] = $id;
|
||||
|
||||
$form = Form::make($header);
|
||||
$tpl = $action == 'print' ? 'print' : 'create';
|
||||
return $this->display([
|
||||
'form' => $form,
|
||||
], $tpl);
|
||||
}
|
||||
|
||||
// 编辑
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
// 审核
|
||||
public function auditAction()
|
||||
{
|
||||
return $this->createAction('audit');
|
||||
}
|
||||
|
||||
// 显示
|
||||
public function showAction()
|
||||
{
|
||||
return $this->createAction('show');
|
||||
}
|
||||
|
||||
// 打印
|
||||
public function printAction()
|
||||
{
|
||||
$id = Request::get('id');
|
||||
$template_id = Request::get('template_id');
|
||||
|
||||
$this->layout = 'layouts.print3';
|
||||
$master = DB::table('stock_cancel as sd')
|
||||
->leftJoin('customer as c', 'c.id', '=', 'sd.customer_id')
|
||||
->leftJoin('customer_tax as ct', 'ct.id', '=', 'sd.tax_id')
|
||||
->leftJoin('sale_type as st', 'st.id', '=', 'sd.type_id')
|
||||
->selectRaw('sd.*, ct.name as tax_name, c.name as customer_name, st.name as type_name')
|
||||
->where('sd.id', $id)
|
||||
->first();
|
||||
|
||||
$model = DB::table('stock_cancel_data as sdd')
|
||||
->leftJoin('stock_cancel as sd', 'sd.id', '=', 'sdd.cancel_id')
|
||||
->leftJoin('product as p', 'p.id', '=', 'sdd.product_id')
|
||||
->leftJoin('product_unit as pu', 'pu.id', '=', 'p.unit_id')
|
||||
->leftJoin('customer_order_type as cot', 'cot.id', '=', 'sdd.type_id')
|
||||
->leftJoin('warehouse as w', 'w.id', '=', 'sdd.warehouse_id')
|
||||
->where('sdd.cancel_id', $id);
|
||||
|
||||
$rows = $model->selectRaw("
|
||||
sdd.*,
|
||||
p.name as product_name,
|
||||
p.spec as product_spec,
|
||||
cot.name as type_name,
|
||||
pu.name as product_unit,
|
||||
p.material_type,
|
||||
p.product_type
|
||||
")
|
||||
->orderBy('p.code', 'asc')
|
||||
->get();
|
||||
|
||||
$form = [
|
||||
'template' => DB::table('model_template')->where('id', $template_id)->first()
|
||||
];
|
||||
|
||||
return $this->display([
|
||||
'master' => $master,
|
||||
'rows' => $rows,
|
||||
'form' => $form,
|
||||
], 'print/'.$template_id);
|
||||
}
|
||||
|
||||
// 批量编辑
|
||||
public function batchEditAction()
|
||||
{
|
||||
$gets = Request::all();
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = explode(',', $gets['ids']);
|
||||
DB::table('stock_cancel')->whereIn('id', $ids)->update([
|
||||
$gets['field'] => $gets['search_0'],
|
||||
]);
|
||||
return $this->json('修改完成。', true);
|
||||
}
|
||||
$header = Grid::batchEdit([
|
||||
'code' => 'stock_cancel',
|
||||
'columns' => ['customer_id', 'tax_id'],
|
||||
]);
|
||||
return view('batchEdit', [
|
||||
'gets' => $gets,
|
||||
'header' => $header
|
||||
]);
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'stock_cancel', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php namespace Gdoo\Stock\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Stock\Models\StockCategory;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class CategoryController extends DefaultController
|
||||
{
|
||||
public $permission = ['dialog'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'stock_type',
|
||||
'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'])
|
||||
->orderBy('id', 'desc');
|
||||
|
||||
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'] = StockCategory::$tabs;
|
||||
$header['bys'] = StockCategory::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建客户联系人
|
||||
public function createAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$form = Form::make(['code' => 'stock_type', 'id' => $id]);
|
||||
return $this->render([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 创建客户联系人
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹出层信息
|
||||
*/
|
||||
public function dialogAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'stock_type',
|
||||
]);
|
||||
$search = $header['search_form'];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table($header['table']);
|
||||
foreach ($header['join'] as $join) {
|
||||
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
|
||||
}
|
||||
$model->where('stock_type.status', 1)
|
||||
->orderBy('stock_type.sort', 'asc');
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
$model->select($header['select']);
|
||||
|
||||
$rows = $model->paginate($query['limit']);
|
||||
$items = Grid::dataFilters($rows, $header, function($item) {
|
||||
return $item;
|
||||
});
|
||||
return response()->json($items);
|
||||
}
|
||||
|
||||
return $this->render([
|
||||
'search' => $search,
|
||||
], 'dialog');
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'stock_type', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,470 @@
|
||||
<?php namespace Gdoo\Stock\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use App\Support\AES;
|
||||
|
||||
use Gdoo\Stock\Models\Delivery;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Model\Models\Bill;
|
||||
use Gdoo\Model\Models\Step;
|
||||
use Gdoo\Model\Models\Run;
|
||||
|
||||
use Gdoo\Model\Services\ModelService;
|
||||
use Gdoo\Model\Services\StepService;
|
||||
use Gdoo\Stock\Services\StockService;
|
||||
|
||||
use Gdoo\Index\Controllers\WorkflowController;
|
||||
|
||||
class DeliveryController extends WorkflowController
|
||||
{
|
||||
public $permission = [
|
||||
'dialog',
|
||||
'logistics',
|
||||
'getBatchSelect',
|
||||
'getBatchSelectAll',
|
||||
'getBatchSelectZY',
|
||||
'autoSave'
|
||||
];
|
||||
|
||||
// 发货列表
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'stock_delivery',
|
||||
'referer' => 1,
|
||||
'search' => ['by' => ''],
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '显示',
|
||||
'action' => 'show',
|
||||
'display' => $this->access['show'],
|
||||
]];
|
||||
|
||||
$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']);
|
||||
|
||||
// 过滤库管角色 辅料:30, 成品:31
|
||||
if (auth()->user()->role_id == 30) {
|
||||
$model->where('stock_delivery.type_id', 2);
|
||||
}
|
||||
if (auth()->user()->role_id == 31) {
|
||||
$model->where('stock_delivery.type_id', '<>', 2);
|
||||
}
|
||||
|
||||
// 发货统计
|
||||
$model->leftJoin(DB::raw('(select SUM(ISNULL(d.quantity, 0)) total_quantity, d.delivery_id
|
||||
FROM stock_delivery_data as d
|
||||
GROUP BY d.delivery_id
|
||||
) sdd
|
||||
'), 'stock_delivery.id', '=', 'sdd.delivery_id');
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
// 客户权限
|
||||
$region = regionCustomer('customer_id_customer');
|
||||
if ($region['authorise']) {
|
||||
foreach ($region['whereIn'] as $key => $where) {
|
||||
$model->whereIn($key, $where);
|
||||
}
|
||||
}
|
||||
|
||||
$model->select($header['select']);
|
||||
$model->addSelect(DB::raw('sdd.total_quantity'));
|
||||
|
||||
$rows = $model->paginate($query['limit'])->appends($query);
|
||||
$items = Grid::dataFilters($rows, $header);
|
||||
return $items->toJson();
|
||||
}
|
||||
|
||||
$header['buttons'] = [
|
||||
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['left_buttons'] = [
|
||||
['name' => '批量编辑', 'color' => 'default', 'icon' => 'fa-pencil-square-o', 'action' => 'batchEdit', 'display' => $this->access['batchEdit']],
|
||||
];
|
||||
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = Delivery::$tabs;
|
||||
$header['bys'] = Delivery::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 明细列表
|
||||
public function detailAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'stock_delivery',
|
||||
'referer' => 1,
|
||||
'template_id' => 71,
|
||||
'search' => ['by' => ''],
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '显示',
|
||||
'action' => 'show',
|
||||
'display' => $this->access['show'],
|
||||
]];
|
||||
|
||||
$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']);
|
||||
|
||||
// 过滤库管角色 辅料:30, 成品:31
|
||||
if (auth()->user()->role_id == 30) {
|
||||
$model->where('stock_delivery.type_id', 2);
|
||||
}
|
||||
if (auth()->user()->role_id == 31) {
|
||||
$model->where('stock_delivery.type_id', '<>', 2);
|
||||
}
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
// 客户权限
|
||||
$region = regionCustomer('customer_id_customer');
|
||||
if ($region['authorise']) {
|
||||
foreach ($region['whereIn'] as $key => $where) {
|
||||
$model->whereIn($key, $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-share', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = Delivery::$tabs2;
|
||||
$header['bys'] = Delivery::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 自动保存
|
||||
public function autoSaveAction()
|
||||
{
|
||||
$gets = Request::all();
|
||||
$master = $gets['master'];
|
||||
$keys = AES::decrypt($master['key'], config('app.key'));
|
||||
list($bill_id, $id) = explode('.', $keys);
|
||||
$bill = Bill::find($bill_id);
|
||||
|
||||
// 发货日期为空
|
||||
if (empty($gets['stock_delivery']['invoice_dt'])) {
|
||||
$gets['stock_delivery']['invoice_dt'] = date('Y-m-d');
|
||||
}
|
||||
|
||||
$models = ModelService::getModels($bill->model_id);
|
||||
if (Request::method() == 'POST') {
|
||||
$rows = $gets['stock_delivery_data']['rows'];
|
||||
$product_ids = [];
|
||||
foreach($rows as $row) {
|
||||
$product_ids[$row['product_id']] = $row['product_id'];
|
||||
}
|
||||
|
||||
// 获取产品列表
|
||||
$vars2 = DB::table('product')->whereIn('id', $product_ids)->get()->keyBy('id');
|
||||
$materiels = $products = [];
|
||||
foreach($rows as $row) {
|
||||
$product = $vars2[$row['product_id']];
|
||||
if ($product['material_type'] > 0) {
|
||||
$materiels[] = $row;
|
||||
} else {
|
||||
$products[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
$print_ids = [];
|
||||
if (count($products) > 0) {
|
||||
$gets['stock_delivery']['type_id'] = 1;
|
||||
$gets['stock_delivery_data']['rows'] = $products;
|
||||
$id = Form::store($bill, $models, $gets, 0);
|
||||
$print_ids[] = $id;
|
||||
}
|
||||
|
||||
if (count($materiels) > 0) {
|
||||
$gets['stock_delivery']['type_id'] = 2;
|
||||
$gets['stock_delivery_data']['rows'] = $materiels;
|
||||
$id = Form::store($bill, $models, $gets, 0);
|
||||
$print_ids[] = $id;
|
||||
}
|
||||
|
||||
foreach($print_ids as $print_id) {
|
||||
DB::table('stock_delivery')->where('id', $print_id)->update(['print_master_id' => $print_ids[0]]);
|
||||
}
|
||||
|
||||
// 自动保存发货单返回数据
|
||||
$url = url($master['uri'].'/show', ['id' => $id, 'client' => $master['client']]);
|
||||
return $this->json($bill['name'].'保存成功', $url);
|
||||
}
|
||||
return $this->createAction('audit');
|
||||
}
|
||||
|
||||
// 新建
|
||||
public function createAction($action = 'edit')
|
||||
{
|
||||
$id = (int) Request::get('id');
|
||||
$header['action'] = $action;
|
||||
$header['code'] = 'stock_delivery';
|
||||
$header['id'] = $id;
|
||||
|
||||
// 客户权限
|
||||
$header['region'] = ['field' => 'customer_id'];
|
||||
$header['authorise'] = ['action' => 'index', 'field' => 'created_id'];
|
||||
|
||||
$header['select'] = '
|
||||
product_id_product.weight,
|
||||
product_id_product.weight * stock_delivery_data.quantity as total_weight
|
||||
';
|
||||
|
||||
$form = Form::make($header);
|
||||
$tpl = $action == 'print' ? 'print' : 'create';
|
||||
return $this->display([
|
||||
'form' => $form,
|
||||
], $tpl);
|
||||
}
|
||||
|
||||
// 编辑
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
// 审核
|
||||
public function auditAction()
|
||||
{
|
||||
return $this->createAction('audit');
|
||||
}
|
||||
|
||||
// 显示
|
||||
public function showAction()
|
||||
{
|
||||
return $this->createAction('show');
|
||||
}
|
||||
|
||||
// 批量编辑
|
||||
public function batchEditAction()
|
||||
{
|
||||
$gets = Request::all();
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = explode(',', $gets['ids']);
|
||||
DB::table('stock_delivery')->whereIn('id', $ids)->update([
|
||||
$gets['field'] => $gets['search_0'],
|
||||
]);
|
||||
return $this->json('修改完成。', true);
|
||||
}
|
||||
$header = Grid::batchEdit([
|
||||
'code' => 'stock_delivery',
|
||||
'columns' => ['customer_id', 'tax_id'],
|
||||
]);
|
||||
return view('batchEdit', [
|
||||
'gets' => $gets,
|
||||
'header' => $header
|
||||
]);
|
||||
}
|
||||
|
||||
// 打印
|
||||
public function printAction()
|
||||
{
|
||||
$id = Request::get('id');
|
||||
$template_id = Request::get('template_id');
|
||||
|
||||
$master = DB::table('stock_delivery as sd')
|
||||
->leftJoin('customer as c', 'c.id', '=', 'sd.customer_id')
|
||||
->leftJoin('customer_tax as ct', 'ct.id', '=', 'sd.tax_id')
|
||||
->leftJoin('sale_type as st', 'st.id', '=', 'sd.type_id')
|
||||
->selectRaw('sd.*, ct.name as tax_name, c.name as customer_name, st.name as type_name')
|
||||
->where('sd.id', $id)
|
||||
->first();
|
||||
|
||||
$model = DB::table('stock_delivery_data as sdd')
|
||||
->leftJoin('stock_delivery as sd', 'sd.id', '=', 'sdd.delivery_id')
|
||||
->leftJoin('product as p', 'p.id', '=', 'sdd.product_id')
|
||||
->leftJoin('product_unit as pu', 'pu.id', '=', 'p.unit_id')
|
||||
->leftJoin('customer_order_type as cot', 'cot.id', '=', 'sdd.type_id')
|
||||
->leftJoin('warehouse as w', 'w.id', '=', 'sdd.warehouse_id');
|
||||
|
||||
if ($template_id == 112) {
|
||||
$model->where('sd.print_master_id', $master['print_master_id']);
|
||||
} else {
|
||||
$model->where('sdd.delivery_id', $id);
|
||||
}
|
||||
|
||||
$model->whereRaw("p.code <> '99001'");
|
||||
|
||||
$rows = $model->selectRaw("
|
||||
sdd.*,
|
||||
p.name as product_name,
|
||||
p.spec as product_spec,
|
||||
cot.name as type_name,
|
||||
pu.name as product_unit,
|
||||
p.material_type,
|
||||
p.product_type,
|
||||
SUBSTRING(batch_sn, 3, 4) as batch_sn,
|
||||
case when right(w.name, 4) = '不满件库' then 'B' else '' end warehouse_type
|
||||
")
|
||||
->orderBy('p.code', 'asc')
|
||||
->get();
|
||||
|
||||
$money = DB::table('stock_delivery_data as sdd')
|
||||
->leftJoin('product as p', 'p.id', '=', 'sdd.product_id')
|
||||
->where('sdd.delivery_id', $id)
|
||||
->whereRaw("p.code = '99001'")
|
||||
->sum("money");
|
||||
|
||||
$form = [
|
||||
'template' => DB::table('model_template')->where('id', $template_id)->first()
|
||||
];
|
||||
|
||||
if ($template_id == 87) {
|
||||
$this->layout = 'layouts.print_stiReport';
|
||||
return $this->display([
|
||||
'master' => $master,
|
||||
'money' => $money,
|
||||
'rows' => $rows,
|
||||
'form' => $form,
|
||||
], 'print/'.$template_id);
|
||||
} else {
|
||||
$this->layout = 'layouts.print2';
|
||||
print_prince($this->display([
|
||||
'master' => $master,
|
||||
'money' => $money,
|
||||
'rows' => $rows,
|
||||
'form' => $form,
|
||||
], 'print/'.$template_id));
|
||||
}
|
||||
}
|
||||
|
||||
// 物流信息
|
||||
public function logisticsAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$gets = Request::get('stock_delivery');
|
||||
$id = $gets['id'];
|
||||
$gets['freight_created_dt'] = date('Y-m-d H:i:s');
|
||||
$gets['freight_created_by'] = auth()->user()->name;
|
||||
DB::table('stock_delivery')->where('id', $id)->update($gets);
|
||||
return $this->json('物流信息提交成功。', true);
|
||||
}
|
||||
$file = base_path().'/addons/'.ucfirst(Request::module()).'/views/'.Request::controller().'/'.Request::action().'.xml';
|
||||
$id = Request::get('id');
|
||||
$row = Delivery::find($id);
|
||||
$freight_quantity = floatval($row['freight_quantity']);
|
||||
|
||||
if ($freight_quantity == 0) {
|
||||
$count = DB::table('stock_delivery_data')
|
||||
->where('delivery_id', $id)->selectRaw('sum(total_weight) as weight, sum(quantity) as quantity')->first();
|
||||
$weight = intval($count['weight'] / 100);
|
||||
$weight = number_format($weight / 10, 1);
|
||||
$quantity = $count['quantity'];
|
||||
$row['freight_quantity'] = $quantity;
|
||||
$row['freight_weight'] = $weight;
|
||||
}
|
||||
$form = Form::make1(['table' => 'stock_delivery', 'file' => $file, 'row' => $row]);
|
||||
return $form;
|
||||
}
|
||||
|
||||
// 获取库存(不含不满件)
|
||||
public function getBatchSelectAction()
|
||||
{
|
||||
$search = search_form(['advanced' => ''], [
|
||||
['form_type' => 'text', 'name' => '产品名称', 'field' => 'name'],
|
||||
['form_type' => 'text', 'name' => '产品编码', 'field' => 'code']
|
||||
], 'model');
|
||||
$query = $search['query'];
|
||||
if (Request::method() == 'POST') {
|
||||
$rows = StockService::getBatchSelect($query['warehouse_id'], $query['product_id'], $query['value'], $query['customer_id']);
|
||||
return ['data' => $rows];
|
||||
}
|
||||
return $this->render([
|
||||
'search' => $search,
|
||||
]);
|
||||
}
|
||||
|
||||
// 获取库存(直营)
|
||||
public function getBatchSelectZYAction()
|
||||
{
|
||||
$search = search_form(['advanced' => ''], [
|
||||
['form_type' => 'text', 'name' => '产品名称', 'field' => 'name'],
|
||||
['form_type' => 'text', 'name' => '产品编码', 'field' => 'code']
|
||||
], 'model');
|
||||
$query = $search['query'];
|
||||
if (Request::method() == 'POST') {
|
||||
$rows = StockService::getBatchSelectZY($query['warehouse_id'], $query['product_id'], $query['value']);
|
||||
return ['data' => $rows];
|
||||
}
|
||||
return $this->render([
|
||||
'search' => $search,
|
||||
], 'getBatchSelect');
|
||||
}
|
||||
|
||||
// 获取库存(全部)
|
||||
public function getBatchSelectAllAction()
|
||||
{
|
||||
$search = search_form(['advanced' => ''], [
|
||||
['form_type' => 'text', 'name' => '产品名称', 'field' => 'name'],
|
||||
['form_type' => 'text', 'name' => '产品编码', 'field' => 'code']
|
||||
], 'model');
|
||||
$query = $search['query'];
|
||||
if (Request::method() == 'POST') {
|
||||
$rows = StockService::getBatchSelectAll($query['warehouse_id'], $query['product_id'], $query['value'], 0);
|
||||
return ['data' => $rows];
|
||||
}
|
||||
return $this->render([
|
||||
'search' => $search,
|
||||
], 'getBatchSelect');
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'stock_delivery', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
<?php namespace Gdoo\Stock\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Stock\Models\Direct;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Index\Controllers\WorkflowController;
|
||||
|
||||
class DirectController extends WorkflowController
|
||||
{
|
||||
public $permission = ['dialog', 'importExcel'];
|
||||
|
||||
// 列表
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'stock_direct',
|
||||
'referer' => 1,
|
||||
'search' => ['by' => ''],
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '显示',
|
||||
'action' => 'show',
|
||||
'display' => $this->access['show'],
|
||||
]];
|
||||
|
||||
$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-share', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = Direct::$tabs;
|
||||
$header['bys'] = Direct::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建
|
||||
public function createAction($action = 'edit')
|
||||
{
|
||||
$id = (int) Request::get('id');
|
||||
$header['action'] = $action;
|
||||
$header['code'] = 'stock_direct';
|
||||
$header['id'] = $id;
|
||||
|
||||
$form = Form::make($header);
|
||||
$tpl = $action == 'print' ? 'print' : 'create';
|
||||
return $this->display([
|
||||
'form' => $form,
|
||||
], $tpl);
|
||||
}
|
||||
|
||||
// 编辑
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
// 审核
|
||||
public function auditAction()
|
||||
{
|
||||
return $this->createAction('audit');
|
||||
}
|
||||
|
||||
// 显示
|
||||
public function showAction()
|
||||
{
|
||||
return $this->createAction('show');
|
||||
}
|
||||
|
||||
// 打印
|
||||
public function printAction()
|
||||
{
|
||||
$id = Request::get('id');
|
||||
$template_id = Request::get('template_id');
|
||||
|
||||
$this->layout = 'layouts.print3';
|
||||
|
||||
$master = DB::table('stock_direct as sd')
|
||||
->leftJoin('customer as c', 'c.id', '=', 'sd.customer_id')
|
||||
->leftJoin('customer_tax as ct', 'ct.id', '=', 'sd.tax_id')
|
||||
->leftJoin('sale_type as st', 'st.id', '=', 'sd.type_id')
|
||||
->selectRaw('sd.*, ct.name as tax_name, c.name as customer_name, st.name as type_name')
|
||||
->where('sd.id', $id)
|
||||
->first();
|
||||
|
||||
$model = DB::table('stock_direct_data as sdd')
|
||||
->leftJoin('stock_direct as sd', 'sd.id', '=', 'sdd.direct_id')
|
||||
->leftJoin('product as p', 'p.id', '=', 'sdd.product_id')
|
||||
->leftJoin('product_unit as pu', 'pu.id', '=', 'p.unit_id')
|
||||
->leftJoin('customer_order_type as cot', 'cot.id', '=', 'sdd.type_id')
|
||||
->leftJoin('warehouse as w', 'w.id', '=', 'sdd.warehouse_id');
|
||||
|
||||
$model->where('sdd.direct_id', $id);
|
||||
|
||||
$model->whereRaw("p.code <> '99001'");
|
||||
|
||||
$rows = $model->selectRaw("
|
||||
sdd.*,
|
||||
p.name as product_name,
|
||||
p.spec as product_spec,
|
||||
cot.name as type_name,
|
||||
pu.name as product_unit,
|
||||
p.material_type,
|
||||
p.product_type,
|
||||
SUBSTRING(batch_sn, 3, 4) as batch_sn,
|
||||
case when right(w.name, 4) = '不满件库' then 'B' else '' end warehouse_type
|
||||
")
|
||||
->orderBy('p.code', 'asc')
|
||||
->get();
|
||||
|
||||
$money = DB::table('stock_direct_data as sdd')
|
||||
->leftJoin('product as p', 'p.id', '=', 'sdd.product_id')
|
||||
->where('sdd.direct_id', $id)
|
||||
->whereRaw("p.code = '99001'")
|
||||
->sum("money");
|
||||
|
||||
$form = [
|
||||
'template' => DB::table('model_template')->where('id', $template_id)->first()
|
||||
];
|
||||
|
||||
return $this->display([
|
||||
'master' => $master,
|
||||
'money' => $money,
|
||||
'rows' => $rows,
|
||||
'form' => $form,
|
||||
], 'print/'.$template_id);
|
||||
}
|
||||
|
||||
public function importExcelAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$customer_id = Request::get('customer_id');
|
||||
$file = Request::file('file');
|
||||
if ($file->isValid()) {
|
||||
$types = DB::table('customer_order_type')->get()->keyBy('name');
|
||||
$customer = DB::table('customer')->where('id', $customer_id)->first();
|
||||
$products = DB::table('customer_price')
|
||||
->leftJoin('product', 'product.id', '=', 'customer_price.product_id')
|
||||
->leftJoin('product_unit', 'product_unit.id', '=', 'product.unit_id')
|
||||
->where('customer_id', $customer_id)
|
||||
->selectRaw('
|
||||
product.*,
|
||||
customer_price.price,
|
||||
product_unit.name as unit_name,
|
||||
product.price'.$customer['type_id'].' as product_price
|
||||
')
|
||||
->get()->keyBy('code');
|
||||
|
||||
/*
|
||||
[0] => 类型
|
||||
[1] => 产品编码
|
||||
[2] => 数量
|
||||
[3] => 单价
|
||||
[4] => 备注
|
||||
*/
|
||||
$rows = readExcel($file->getPathName(), $file->getClientOriginalExtension());
|
||||
$items = [];
|
||||
foreach($rows as $i => $row) {
|
||||
if ($i > 1) {
|
||||
$type = $types[$row[0]];
|
||||
if (empty($type)) {
|
||||
return $this->json('产品编码'.$row[1].':类型('.$row[0].')不存在。');
|
||||
}
|
||||
$product = $products[$row[1]];
|
||||
if (empty($product)) {
|
||||
return $this->json('产品编码'.$row[1].'在客户销售价格中不存在。');
|
||||
}
|
||||
|
||||
if (floatval($row[3]) <> 0) {
|
||||
$price = $row[3];
|
||||
} else {
|
||||
$price = floatval($product['price']) == 0 ? $product['product_price'] : $product['price'];
|
||||
}
|
||||
|
||||
$quantity = $row[2];
|
||||
$item = [
|
||||
'type_id' => $type['id'],
|
||||
'type_id_name' => $type['name'],
|
||||
'product_id' => $product['id'],
|
||||
'product_code' => $product['code'],
|
||||
'product_name' => $product['name'],
|
||||
'product_spec' => $product['spec'],
|
||||
'product_barcode' => $product['barcode'],
|
||||
'product_unit' => $product['unit_name'],
|
||||
'price' => $price,
|
||||
'quantity' => $quantity,
|
||||
'money' => $price * $quantity,
|
||||
'weight' => $product['weight'],
|
||||
'total_weight' => $product['weight'] * $quantity,
|
||||
'remark' => $row[3],
|
||||
];
|
||||
if ($type['id'] == 2) {
|
||||
$item['other_money'] = $item['money'];
|
||||
}
|
||||
$items[] = $item;
|
||||
}
|
||||
}
|
||||
return $this->json($items, true);
|
||||
}
|
||||
}
|
||||
return view('importExcel');
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'stock_direct', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
<?php namespace Gdoo\Stock\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Stock\Models\WarehouseLocation;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class LocationController extends DefaultController
|
||||
{
|
||||
public $permission = ['dialog', 'dialog2', 'serviceWarehouse'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'warehouse_location',
|
||||
'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'])
|
||||
->orderBy('id', 'desc');
|
||||
|
||||
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'] = WarehouseLocation::$tabs;
|
||||
$header['bys'] = WarehouseLocation::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建客户联系人
|
||||
public function createAction($action = 'edit')
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$form = Form::make(['code' => 'warehouse_location', 'id' => $id, 'action' => $action]);
|
||||
return $this->render([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 创建客户联系人
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹出层信息
|
||||
*/
|
||||
public function dialogAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'warehouse_location',
|
||||
]);
|
||||
$search = $header['search_form'];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table($header['table']);
|
||||
foreach ($header['join'] as $join) {
|
||||
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
|
||||
}
|
||||
|
||||
$model->where('warehouse_location.warehouse_id', $query['warehouse_id'])
|
||||
->orderBy('warehouse_location.sort', 'asc');
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
$model->select($header['select']);
|
||||
|
||||
$rows = $model->paginate($query['limit']);
|
||||
$items = Grid::dataFilters($rows, $header, function($item) {
|
||||
return $item;
|
||||
});
|
||||
return response()->json($items);
|
||||
}
|
||||
|
||||
return $this->render([
|
||||
'search' => $search,
|
||||
], 'dialog');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取现存量
|
||||
*/
|
||||
public function dialog2Action()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'warehouse_location',
|
||||
]);
|
||||
$search = $header['search_form'];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table($header['table']);
|
||||
foreach ($header['join'] as $join) {
|
||||
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
|
||||
}
|
||||
$model->where('warehouse_location.status', 1)
|
||||
->orderBy('warehouse_location.sort', 'asc');
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
$model->select($header['select']);
|
||||
|
||||
$rows = $model->paginate($query['limit']);
|
||||
$items = Grid::dataFilters($rows, $header, function($item) {
|
||||
return $item;
|
||||
});
|
||||
return response()->json($items);
|
||||
}
|
||||
|
||||
return $this->render([
|
||||
'search' => $search,
|
||||
], 'dialog2');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取仓库货位
|
||||
*/
|
||||
public function serviceWarehouseAction()
|
||||
{
|
||||
$warehouse_id = Request::get('warehouse_id');
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table('warehouse_location')
|
||||
->where('warehouse_location.warehouse_id', $warehouse_id)
|
||||
->where('warehouse_location.status', 1)
|
||||
->orderBy('warehouse_location.sort', 'asc');
|
||||
return response()->json($model->get());
|
||||
}
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'warehouse_location', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php namespace Gdoo\Stock\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Stock\Models\Record01;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Index\Controllers\AuditController;
|
||||
|
||||
class Record01Controller extends AuditController
|
||||
{
|
||||
public $permission = ['dialog'];
|
||||
|
||||
// 列表
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'stock_record01',
|
||||
'referer' => 1,
|
||||
'search' => ['by' => ''],
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '显示',
|
||||
'action' => 'show',
|
||||
'display' => $this->access['show'],
|
||||
]];
|
||||
|
||||
$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'] = Record01::$tabs;
|
||||
$header['bys'] = Record01::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建
|
||||
public function createAction($action = 'edit')
|
||||
{
|
||||
$id = (int) Request::get('id');
|
||||
$header['action'] = $action;
|
||||
$header['code'] = 'stock_record01';
|
||||
$header['id'] = $id;
|
||||
|
||||
$form = Form::make($header);
|
||||
$tpl = $action == 'print' ? 'print' : 'create';
|
||||
return $this->display([
|
||||
'form' => $form,
|
||||
], $tpl);
|
||||
}
|
||||
|
||||
// 编辑
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
// 显示
|
||||
public function showAction()
|
||||
{
|
||||
return $this->createAction('show');
|
||||
}
|
||||
|
||||
// 打印
|
||||
public function printAction()
|
||||
{
|
||||
$this->layout = 'layouts.print2';
|
||||
print_prince($this->createAction('print'));
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'stock_record01', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
<?php namespace Gdoo\Stock\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Stock\Models\Record08;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Index\Controllers\AuditController;
|
||||
|
||||
class Record08Controller extends AuditController
|
||||
{
|
||||
public $permission = ['dialog', 'importExcel'];
|
||||
|
||||
// 列表
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'stock_record08',
|
||||
'referer' => 1,
|
||||
'search' => ['by' => ''],
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '显示',
|
||||
'action' => 'show',
|
||||
'display' => $this->access['show'],
|
||||
]];
|
||||
|
||||
$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'] = Record08::$tabs;
|
||||
$header['bys'] = Record08::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建
|
||||
public function createAction($action = 'edit')
|
||||
{
|
||||
$id = (int) Request::get('id');
|
||||
$header['action'] = $action;
|
||||
$header['code'] = 'stock_record08';
|
||||
$header['id'] = $id;
|
||||
|
||||
$form = Form::make($header);
|
||||
$tpl = $action == 'print' ? 'print' : 'create';
|
||||
return $this->display([
|
||||
'form' => $form,
|
||||
], $tpl);
|
||||
}
|
||||
|
||||
// 编辑
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
// 显示
|
||||
public function showAction()
|
||||
{
|
||||
return $this->createAction('show');
|
||||
}
|
||||
|
||||
// 打印
|
||||
public function printAction()
|
||||
{
|
||||
$this->layout = 'layouts.print2';
|
||||
print_prince($this->createAction('print'));
|
||||
}
|
||||
|
||||
public function importExcelAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$file = Request::file('file');
|
||||
|
||||
if ($file->isValid()) {
|
||||
$products = DB::table('product')
|
||||
->leftJoin('product_unit', 'product_unit.id', '=', 'product.unit_id')
|
||||
->selectRaw('
|
||||
product.*,
|
||||
product_unit.name as unit_name
|
||||
')
|
||||
->get()
|
||||
->keyBy('code');
|
||||
/*
|
||||
[0] => 存货编码
|
||||
[1] => 存货名称
|
||||
[2] => 规格型号
|
||||
[3] => 批次
|
||||
[4] => 数量
|
||||
*/
|
||||
$rows = readExcel($file->getPathName(), $file->getClientOriginalExtension());
|
||||
$items = [];
|
||||
foreach($rows as $i => $row) {
|
||||
if ($i > 1) {
|
||||
if ($row[0]) {
|
||||
$product = $products[$row[0]];
|
||||
if (empty($product)) {
|
||||
return $this->json('产品编码'.$product[0].':产品('.$product[1].')不存在。');
|
||||
}
|
||||
$batch_sn = $row[3];
|
||||
$quantity = $row[4];
|
||||
$item = [
|
||||
'product_id' => $product['id'],
|
||||
'product_code' => $product['code'],
|
||||
'product_name' => $product['name'],
|
||||
'product_spec' => $product['spec'],
|
||||
'product_unit' => $product['unit_name'],
|
||||
'quantity' => $quantity,
|
||||
'batch_sn' => $batch_sn,
|
||||
];
|
||||
$items[] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->json($items, true);
|
||||
}
|
||||
}
|
||||
return view('importExcel');
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'stock_record08', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
<?php namespace Gdoo\Stock\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Stock\Models\Record09;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Index\Controllers\WorkflowController;
|
||||
|
||||
class Record09Controller extends WorkflowController
|
||||
{
|
||||
public $permission = ['dialog'];
|
||||
|
||||
// 列表
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'stock_record09',
|
||||
'referer' => 1,
|
||||
'search' => ['by' => ''],
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '显示',
|
||||
'action' => 'show',
|
||||
'display' => $this->access['show'],
|
||||
]];
|
||||
|
||||
$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'] = Record09::$tabs;
|
||||
$header['bys'] = Record09::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建
|
||||
public function createAction($action = 'edit')
|
||||
{
|
||||
$id = (int) Request::get('id');
|
||||
$header['action'] = $action;
|
||||
$header['code'] = 'stock_record09';
|
||||
$header['id'] = $id;
|
||||
|
||||
$form = Form::make($header);
|
||||
$tpl = $action == 'print' ? 'print' : 'create';
|
||||
return $this->display([
|
||||
'form' => $form,
|
||||
], $tpl);
|
||||
}
|
||||
|
||||
// 编辑
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
// 审核
|
||||
public function auditAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
// 显示
|
||||
public function showAction()
|
||||
{
|
||||
return $this->createAction('show');
|
||||
}
|
||||
|
||||
// 打印
|
||||
public function printAction()
|
||||
{
|
||||
$id = Request::get('id');
|
||||
$template_id = Request::get('template_id');
|
||||
|
||||
$this->layout = 'layouts.print3';
|
||||
$master = DB::table('stock_record09 as m')->where('m.id', $id)
|
||||
->leftJoin('stock_type as st', 'st.id', '=', 'm.type_id')
|
||||
->leftJoin('department', 'department.id', '=', 'm.department_id')
|
||||
->leftJoin('warehouse', 'warehouse.id', '=', 'm.warehouse_id')
|
||||
->selectRaw('m.*, st.name as type_name, warehouse.name as warehouse_name, department.name as department_name')
|
||||
->first();
|
||||
|
||||
$rows = DB::table('stock_record09_data as d')
|
||||
->leftJoin('stock_record09 as m', 'm.id', '=', 'd.record09_id')
|
||||
->leftJoin('product as p', 'p.id', '=', 'd.product_id')
|
||||
->leftJoin('product_unit as pu', 'pu.id', '=', 'p.unit_id')
|
||||
->leftJoin('stock_type as st', 'st.id', '=', 'm.type_id')
|
||||
->where('m.id', $id)
|
||||
->selectRaw('
|
||||
d.*,
|
||||
p.name as product_name,
|
||||
p.code as product_code,
|
||||
p.spec as product_spec,
|
||||
st.name as type_name,
|
||||
pu.name as product_unit
|
||||
')
|
||||
->orderBy('p.code', 'asc')
|
||||
->get();
|
||||
|
||||
$form = [
|
||||
'template' => DB::table('model_template')->where('id', $template_id)->first()
|
||||
];
|
||||
|
||||
$tpl = $this->display([
|
||||
'master' => $master,
|
||||
'rows' => $rows,
|
||||
'form' => $form,
|
||||
], 'print/'.$template_id);
|
||||
return $tpl;
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'stock_record09', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
<?php namespace Gdoo\Stock\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Stock\Models\Record10;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Index\Controllers\WorkflowController;
|
||||
|
||||
class Record10Controller extends WorkflowController
|
||||
{
|
||||
public $permission = ['dialog', 'print3'];
|
||||
|
||||
// 列表
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'stock_record10',
|
||||
'referer' => 1,
|
||||
'search' => ['by' => ''],
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '显示',
|
||||
'action' => 'show',
|
||||
'display' => $this->access['show'],
|
||||
]];
|
||||
|
||||
$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']);
|
||||
|
||||
// 川南库管登录
|
||||
if (auth()->id() == 2177) {
|
||||
$model->whereIn('stock_record10.warehouse_id', [20001, 20047]);
|
||||
} else {
|
||||
$model->whereNotIn('stock_record10.warehouse_id', [20001, 20047]);
|
||||
}
|
||||
|
||||
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'] = Record10::$tabs;
|
||||
$header['bys'] = Record10::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建
|
||||
public function createAction($action = 'edit')
|
||||
{
|
||||
$id = (int) Request::get('id');
|
||||
$header['action'] = $action;
|
||||
$header['code'] = 'stock_record10';
|
||||
$header['id'] = $id;
|
||||
|
||||
$form = Form::make($header);
|
||||
|
||||
$tpl = $action == 'print' ? 'print' : 'create';
|
||||
return $this->display([
|
||||
'form' => $form,
|
||||
], $tpl);
|
||||
}
|
||||
|
||||
// 编辑
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
// 审核
|
||||
public function auditAction()
|
||||
{
|
||||
return $this->createAction('audit');
|
||||
}
|
||||
|
||||
// 显示
|
||||
public function showAction()
|
||||
{
|
||||
return $this->createAction('show');
|
||||
}
|
||||
|
||||
// 打印
|
||||
public function print2Action()
|
||||
{
|
||||
$this->layout = 'layouts.print2';
|
||||
$view = $this->createAction('print');
|
||||
$viewData = $view->getData();
|
||||
print_prince($this->createAction('print'));
|
||||
}
|
||||
|
||||
// 显示促销
|
||||
public function printAction()
|
||||
{
|
||||
$id = Request::get('id');
|
||||
$template_id = Request::get('template_id');
|
||||
if ($template_id == 117) {
|
||||
|
||||
$this->layout = 'layouts.print3';
|
||||
|
||||
$master = DB::table('stock_record10 as m')->where('m.id', $id)
|
||||
->leftJoin('stock_type as st', 'st.id', '=', 'm.type_id')
|
||||
->leftJoin('department', 'department.id', '=', 'm.department_id')
|
||||
->leftJoin('warehouse', 'warehouse.id', '=', 'm.warehouse_id')
|
||||
->selectRaw('m.*, st.name as type_name, warehouse.name as warehouse_name, department.name as department_name')
|
||||
->first();
|
||||
|
||||
$rows = DB::table('stock_record10_data as d')
|
||||
->leftJoin('stock_record10 as m', 'm.id', '=', 'd.record10_id')
|
||||
->leftJoin('product as p', 'p.id', '=', 'd.product_id')
|
||||
->leftJoin('product_unit as pu', 'pu.id', '=', 'p.unit_id')
|
||||
->leftJoin('stock_type as st', 'st.id', '=', 'm.type_id')
|
||||
->where('m.id', $id)
|
||||
->selectRaw('
|
||||
d.*,
|
||||
p.name as product_name,
|
||||
p.code as product_code,
|
||||
p.spec as product_spec,
|
||||
st.name as type_name,
|
||||
pu.name as product_unit
|
||||
')
|
||||
->get();
|
||||
|
||||
$form = [
|
||||
'template' => DB::table('model_template')->where('id', $template_id)->first()
|
||||
];
|
||||
|
||||
$tpl = $this->display([
|
||||
'master' => $master,
|
||||
'rows' => $rows,
|
||||
'form' => $form,
|
||||
], 'print/'.$template_id);
|
||||
return $tpl;
|
||||
|
||||
} else {
|
||||
$this->layout = 'layouts.print2';
|
||||
$tpl = $this->createAction('print');
|
||||
print_prince($tpl);
|
||||
}
|
||||
}
|
||||
|
||||
// 显示促销
|
||||
public function print3Action()
|
||||
{
|
||||
$this->layout = 'layouts.print2';
|
||||
$id = Request::get('id');
|
||||
$template_id = Request::get('template_id');
|
||||
if ($template_id == 117) {
|
||||
|
||||
$this->layout = 'layouts.print2';
|
||||
|
||||
$master = DB::table('stock_record10 as m')->where('m.id', $id)
|
||||
->leftJoin('stock_type as st', 'st.id', '=', 'm.type_id')
|
||||
->leftJoin('department', 'department.id', '=', 'm.department_id')
|
||||
->leftJoin('warehouse', 'warehouse.id', '=', 'm.warehouse_id')
|
||||
->selectRaw('m.*, st.name as type_name, warehouse.name as warehouse_name, department.name as department_name')
|
||||
->first();
|
||||
|
||||
$rows = DB::table('stock_record10_data as d')
|
||||
->leftJoin('stock_record10 as m', 'm.id', '=', 'd.record10_id')
|
||||
->leftJoin('product as p', 'p.id', '=', 'd.product_id')
|
||||
->leftJoin('product_unit as pu', 'pu.id', '=', 'p.unit_id')
|
||||
->leftJoin('stock_type as st', 'st.id', '=', 'm.type_id')
|
||||
->where('m.id', $id)
|
||||
->selectRaw('
|
||||
d.*,
|
||||
p.name as product_name,
|
||||
p.code as product_code,
|
||||
p.spec as product_spec,
|
||||
st.name as type_name,
|
||||
pu.name as product_unit
|
||||
')
|
||||
->get();
|
||||
|
||||
$form = [
|
||||
'template' => DB::table('model_template')->where('id', $template_id)->first()
|
||||
];
|
||||
|
||||
$template = "report.fr3";
|
||||
$ver = 3.0;
|
||||
|
||||
$id = (int) Request::get('id');
|
||||
$header['action'] = 'print';
|
||||
$header['code'] = 'stock_record10';
|
||||
$header['id'] = $id;
|
||||
$form = Form::make($header);
|
||||
|
||||
$Tables = [];
|
||||
foreach($form['prints'] as $print) {
|
||||
$fields = [];
|
||||
foreach($print['fields'] as $field) {
|
||||
$type = 'str';
|
||||
$size = 255;
|
||||
if ($field['type'] == 'INT' || $field['type'] == 'TINYINT') {
|
||||
$type = 'int';
|
||||
$size = 0;
|
||||
}
|
||||
if ($field['type'] == 'DATE') {
|
||||
$type = 'str';
|
||||
}
|
||||
if ($field['type'] == 'DECIMAL') {
|
||||
$type = 'float';
|
||||
$size = 0;
|
||||
}
|
||||
$fields[] = ["type" => $type, "size" => $size, "name" => $field['field'], "required" => false];
|
||||
}
|
||||
$Tables[] = [
|
||||
'Name' => $print['name'],
|
||||
'Cols' => $fields,
|
||||
'Data' => $print['data'],
|
||||
];
|
||||
}
|
||||
$jsonObject = [
|
||||
"template" => $template,
|
||||
"ver" => $ver,
|
||||
"Tables" => $Tables,
|
||||
];
|
||||
|
||||
$jsonStr = json_encode($jsonObject);
|
||||
|
||||
|
||||
$tpl = $this->display([
|
||||
'master' => $master,
|
||||
'jsonStr' => $jsonStr,
|
||||
'rows' => $rows,
|
||||
'form' => $form,
|
||||
], 'print3/'.$template_id);
|
||||
return $tpl;
|
||||
|
||||
} else {
|
||||
$tpl = $this->createAction('print');
|
||||
print_prince($tpl);
|
||||
}
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'stock_record10', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
<?php namespace Gdoo\Stock\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Stock\Models\Record11;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Index\Controllers\AuditController;
|
||||
|
||||
class Record11Controller extends AuditController
|
||||
{
|
||||
public $permission = ['dialog'];
|
||||
|
||||
// 列表
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'stock_record11',
|
||||
'referer' => 1,
|
||||
'search' => ['by' => ''],
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '显示',
|
||||
'action' => 'show',
|
||||
'display' => $this->access['show'],
|
||||
]];
|
||||
|
||||
$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-share', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = Record11::$tabs;
|
||||
$header['bys'] = Record11::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建
|
||||
public function createAction($action = 'edit')
|
||||
{
|
||||
$id = (int) Request::get('id');
|
||||
$header['action'] = $action;
|
||||
$header['code'] = 'stock_record11';
|
||||
$header['id'] = $id;
|
||||
|
||||
$form = Form::make($header);
|
||||
$tpl = $action == 'print' ? 'print' : 'create';
|
||||
return $this->display([
|
||||
'form' => $form,
|
||||
], $tpl);
|
||||
}
|
||||
|
||||
// 编辑
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
// 显示
|
||||
public function showAction()
|
||||
{
|
||||
return $this->createAction('show');
|
||||
}
|
||||
|
||||
// 打印
|
||||
public function printAction()
|
||||
{
|
||||
$id = Request::get('id');
|
||||
$template_id = Request::get('template_id');
|
||||
if ($template_id == 115) {
|
||||
|
||||
$this->layout = 'layouts.print3';
|
||||
|
||||
$master = DB::table('stock_record11 as m')->where('m.id', $id)
|
||||
->leftJoin('stock_type as st', 'st.id', '=', 'm.type_id')
|
||||
->leftJoin('department', 'department.id', '=', 'm.department_id')
|
||||
->leftJoin('warehouse', 'warehouse.id', '=', 'm.warehouse_id')
|
||||
->selectRaw('m.*, st.name as type_name, warehouse.name as warehouse_name, department.name as department_name')
|
||||
->first();
|
||||
|
||||
$rows = DB::table('stock_record11_data as d')
|
||||
->leftJoin('stock_record11 as m', 'm.id', '=', 'd.record11_id')
|
||||
->leftJoin('product as p', 'p.id', '=', 'd.product_id')
|
||||
->leftJoin('product_unit as pu', 'pu.id', '=', 'p.unit_id')
|
||||
->leftJoin('stock_type as st', 'st.id', '=', 'm.type_id')
|
||||
->where('m.id', $id)
|
||||
->selectRaw('
|
||||
d.*,
|
||||
p.name as product_name,
|
||||
p.code as product_code,
|
||||
p.spec as product_spec,
|
||||
st.name as type_name,
|
||||
pu.name as product_unit
|
||||
')
|
||||
->orderBy('p.code', 'asc')
|
||||
->get();
|
||||
|
||||
$form = [
|
||||
'template' => DB::table('model_template')->where('id', $template_id)->first()
|
||||
];
|
||||
|
||||
$tpl = $this->display([
|
||||
'master' => $master,
|
||||
'rows' => $rows,
|
||||
'form' => $form,
|
||||
], 'print/'.$template_id);
|
||||
return $tpl;
|
||||
|
||||
} else {
|
||||
$this->layout = 'layouts.print2';
|
||||
$tpl = $this->createAction('print');
|
||||
print_prince($tpl);
|
||||
}
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'stock_record11', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
<?php namespace Gdoo\Stock\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\Stock\Services\StockService;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class ReportController extends DefaultController
|
||||
{
|
||||
public $permission = [];
|
||||
|
||||
// 库存明细表
|
||||
public function stockDetailAction()
|
||||
{
|
||||
$sdate = date('Y-m-01');
|
||||
$edate = date('Y-m-d');
|
||||
$search = search_form([
|
||||
'advanced' => 0,
|
||||
], [
|
||||
['form_type' => 'dialog', 'name' => '仓库', 'field' => 'warehouse_id', 'options' => ['url' => 'stock/warehouse/dialog', 'query' => ['multi'=>0]]],
|
||||
['form_type' => 'dialog', 'name' => '产品', 'field' => 'product_id', 'options' => ['url' => 'product/product/dialog', 'query' => ['multi'=>0]]],
|
||||
['form_type' => 'text', 'name' => '批号', 'field' => 'batch_sn', 'options' => []],
|
||||
['form_type' => 'select', 'name' => '内销/外销', 'field' => 'type', 'options' => [['id'=>'内销','name'=>'内销'],['id'=>'外贸','name'=>'外贸']]],
|
||||
//['form_type' => 'select', 'name' => '是否统计批号', 'field' => 'batch', 'value' => 0, 'options' => [['id'=>1,'name'=>'是'],['id'=>0,'name'=>'否']]],
|
||||
['form_type' => 'select', 'name' => '包含不满件库', 'field' => 'bmj', 'value' => 0, 'options' => [['id'=>1,'name'=>'是'],['id'=>0,'name'=>'否']]],
|
||||
['form_type' => 'date2', 'name' => '单据日期', 'field' => 'date', 'value' => [$sdate, $edate], 'options' => []],
|
||||
], 'model');
|
||||
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$fields = [];
|
||||
foreach($search['forms']['field'] as $i => $field) {
|
||||
$fields[$field] = $search['forms']['search'][$i];
|
||||
}
|
||||
$rows = [];
|
||||
if ($query['filter'] == 1) {
|
||||
$rows = StockService::reportOrderStockDetail(
|
||||
$fields['warehouse_id'],
|
||||
$fields['product_id'],
|
||||
$fields['batch_sn'],
|
||||
$fields['type'],
|
||||
$fields['date'][0],
|
||||
$fields['date'][1],
|
||||
auth()->id(),
|
||||
$fields['bmj']
|
||||
);
|
||||
$QmNum = 0;
|
||||
foreach($rows as $i => $row) {
|
||||
if ($row['bill_name'] == '期初') {
|
||||
$QmNum = (float)$row['qm_num'];
|
||||
} else {
|
||||
$QmNum = ((float)$row['rk_num'] - (float)$row['ck_num']) + $QmNum;
|
||||
}
|
||||
$row['qm_num'] = $QmNum;
|
||||
$row['id'] = $i + 1;
|
||||
$rows[$i] = $row;
|
||||
}
|
||||
}
|
||||
return $this->json($rows, true);
|
||||
}
|
||||
$search['table'] = 'material_plan';
|
||||
return $this->display([
|
||||
'search' => $search,
|
||||
'query' => $query,
|
||||
]);
|
||||
}
|
||||
|
||||
// 库存汇总表
|
||||
public function stockTotalAction()
|
||||
{
|
||||
$search = search_form([
|
||||
'advanced' => 0,
|
||||
], [
|
||||
['form_type' => 'dialog', 'name' => '仓库', 'field' => 'warehouse_id', 'options' => ['url' => 'stock/warehouse/dialog', 'query' => ['multi'=>0]]],
|
||||
['form_type' => 'text', 'name' => '存货编码', 'field' => 'product_code', 'options' => []],
|
||||
['form_type' => 'select', 'name' => '内销/外销', 'field' => 'type', 'options' => [['id'=>'1','name'=>'内销'],['id'=>'2','name'=>'外贸']]],
|
||||
['form_type' => 'date2', 'name' => '生产日期', 'field' => 'date', 'value' => [], 'options' => []],
|
||||
['form_type' => 'select', 'name' => '统计批号', 'field' => 'batch', 'value' => 1, 'options' => [['id'=>1,'name'=>'是'],['id'=>0,'name'=>'否']]],
|
||||
['form_type' => 'select', 'name' => '包含不满件库', 'field' => 'bmj', 'value' => 0, 'options' => [['id'=>1,'name'=>'是'],['id'=>0,'name'=>'否']]],
|
||||
|
||||
], 'model');
|
||||
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$fields = [];
|
||||
foreach($search['forms']['field'] as $i => $field) {
|
||||
$fields[$field] = $search['forms']['search'][$i];
|
||||
}
|
||||
$rows = [];
|
||||
if ($query['filter'] == 1) {
|
||||
/*
|
||||
$rows = DB::select('EXEC P_ReportOrderStockTotal ?,?,?,?,?,?,?,?', [
|
||||
$fields['warehouse_id'],
|
||||
$fields['product_code'],
|
||||
$fields['type'],
|
||||
$fields['date'][0],
|
||||
$fields['date'][1],
|
||||
auth()->id(),
|
||||
$fields['batch'],
|
||||
$fields['bmj'],
|
||||
]);
|
||||
*/
|
||||
$rows = StockService::reportOrderStockTotal(
|
||||
$fields['warehouse_id'],
|
||||
$fields['product_code'],
|
||||
$fields['type'],
|
||||
$fields['date'][0],
|
||||
$fields['date'][1],
|
||||
auth()->id(),
|
||||
$fields['batch'],
|
||||
$fields['bmj']
|
||||
);
|
||||
}
|
||||
return $this->json($rows, true);
|
||||
}
|
||||
$search['table'] = 'material_plan';
|
||||
return $this->display([
|
||||
'search' => $search,
|
||||
'query' => $query,
|
||||
]);
|
||||
}
|
||||
|
||||
// 进销存库存汇总表
|
||||
public function stockInOutAction()
|
||||
{
|
||||
$sdate = date('Y-m-01');
|
||||
$edate = date('Y-m-d');
|
||||
$search = search_form([
|
||||
'advanced' => 0,
|
||||
], [
|
||||
['form_type' => 'dialog', 'name' => '仓库', 'field' => 'warehouse_id', 'options' => ['url' => 'stock/warehouse/dialog', 'query' => ['multi'=>0]]],
|
||||
['form_type' => 'dialog', 'name' => '产品', 'field' => 'product_id', 'options' => ['url' => 'product/product/dialog', 'query' => ['multi'=>0]]],
|
||||
['form_type' => 'text', 'name' => '批号', 'field' => 'batch_sn', 'options' => []],
|
||||
['form_type' => 'select', 'name' => '内销/外销', 'field' => 'type', 'options' => [['id'=>'内销','name'=>'内销'],['id'=>'外贸','name'=>'外贸']]],
|
||||
['form_type' => 'select', 'name' => '统计批号', 'field' => 'batch', 'value' => 0, 'options' => [['id'=>1,'name'=>'是'],['id'=>0,'name'=>'否']]],
|
||||
['form_type' => 'select', 'name' => '包含不满件库', 'field' => 'bmj', 'value' => 0, 'options' => [['id'=>1,'name'=>'是'],['id'=>0,'name'=>'否']]],
|
||||
['form_type' => 'date2', 'name' => '单据日期', 'field' => 'date', 'value' => [$sdate, $edate], 'options' => []],
|
||||
], 'model');
|
||||
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$fields = [];
|
||||
foreach($search['forms']['field'] as $i => $field) {
|
||||
$fields[$field] = $search['forms']['search'][$i];
|
||||
}
|
||||
|
||||
$rows = [];
|
||||
if ($query['filter'] == 1) {
|
||||
$rows = StockService::reportOrderStockInOut(
|
||||
$fields['warehouse_id'],
|
||||
$fields['product_id'],
|
||||
$fields['batch_sn'],
|
||||
$fields['type'],
|
||||
$fields['date'][0],
|
||||
$fields['date'][1],
|
||||
auth()->id(),
|
||||
$fields['batch'],
|
||||
$fields['bmj']
|
||||
);
|
||||
}
|
||||
return $this->json($rows, true);
|
||||
}
|
||||
$search['table'] = 'material_plan';
|
||||
return $this->display([
|
||||
'search' => $search,
|
||||
'query' => $query,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php namespace Gdoo\Stock\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Stock\Models\StockType;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class TypeController extends DefaultController
|
||||
{
|
||||
public $permission = ['dialog'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'sale_type',
|
||||
'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'])
|
||||
->orderBy('id', 'desc');
|
||||
|
||||
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'] = StockType::$tabs;
|
||||
$header['bys'] = StockType::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建客户联系人
|
||||
public function createAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$form = Form::make(['code' => 'sale_type', 'id' => $id]);
|
||||
return $this->render([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 创建客户联系人
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹出层信息
|
||||
*/
|
||||
public function dialogAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'sale_type',
|
||||
]);
|
||||
$search = $header['search_form'];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table($header['table']);
|
||||
foreach ($header['join'] as $join) {
|
||||
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
|
||||
}
|
||||
$model->where('sale_type.status', 1)
|
||||
->orderBy('sale_type.sort', 'asc');
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
$model->select($header['select']);
|
||||
|
||||
$rows = $model->paginate($query['limit']);
|
||||
$items = Grid::dataFilters($rows, $header, function($item) {
|
||||
return $item;
|
||||
});
|
||||
return response()->json($items);
|
||||
}
|
||||
|
||||
return $this->render([
|
||||
'search' => $search,
|
||||
], 'dialog');
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'sale_type', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
<?php namespace Gdoo\Stock\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Stock\Models\Warehouse;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class WarehouseController extends DefaultController
|
||||
{
|
||||
public $permission = ['dialog', 'permission'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'warehouse',
|
||||
'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'])
|
||||
->orderBy('id', 'desc');
|
||||
|
||||
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'] = Warehouse::$tabs;
|
||||
$header['bys'] = Warehouse::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建客户联系人
|
||||
public function createAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$form = Form::make(['code' => 'warehouse', 'id' => $id]);
|
||||
return $this->render([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 创建客户联系人
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹出层信息
|
||||
*/
|
||||
public function dialogAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'warehouse',
|
||||
]);
|
||||
$search = $header['search_form'];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table($header['table']);
|
||||
$model->leftJoin('user_warehouse', 'user_warehouse.warehouse_id', '=', 'warehouse.id')
|
||||
->where('user_warehouse.user_id', auth()->id());
|
||||
|
||||
$model->where('warehouse.status', 1)
|
||||
->orderBy('warehouse.id', 'asc');
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
$model->select($header['select']);
|
||||
|
||||
$rows = $model->paginate($query['limit']);
|
||||
|
||||
$_locations = DB::table('warehouse_location')->get();
|
||||
$locations = [];
|
||||
foreach ($_locations as $_location) {
|
||||
$locations[$_location['warehouse_id']][] = $_location;
|
||||
}
|
||||
|
||||
$items = Grid::dataFilters($rows, $header, function($item) use($locations) {
|
||||
$item['pos'] = (array)$locations[$item['id']];
|
||||
return $item;
|
||||
});
|
||||
return response()->json($items);
|
||||
}
|
||||
|
||||
return $this->render([
|
||||
'search' => $search,
|
||||
], 'dialog');
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限设置
|
||||
*/
|
||||
public function permissionAction()
|
||||
{
|
||||
$gets = Request::all();
|
||||
if (Request::method() == 'POST') {
|
||||
$user_id = $gets['user_id'];
|
||||
$rows = $gets['rows'];
|
||||
$users = DB::table('user_warehouse')
|
||||
->where('user_id', $user_id)
|
||||
->pluck('id', 'warehouse_id');
|
||||
foreach($rows as $row) {
|
||||
if (empty($users[$row['id']])) {
|
||||
DB::table('user_warehouse')->insert([
|
||||
'user_id' => $user_id,
|
||||
'warehouse_id' => $row['id']
|
||||
]);
|
||||
} else {
|
||||
unset($users[$row['id']]);
|
||||
}
|
||||
}
|
||||
foreach($users as $warehouse_id) {
|
||||
DB::table('user_warehouse')->where('id', $warehouse_id)->delete();
|
||||
}
|
||||
return $this->json('仓库权限设置成功。', true);
|
||||
}
|
||||
$rows = DB::table('warehouse')->orderBy('id', 'asc')->get(['id', 'code', 'name']);
|
||||
$users = DB::table('user_warehouse')->where('user_id', $gets['user_id'])->pluck('id', 'warehouse_id');
|
||||
return $this->render([
|
||||
'rows' => $rows,
|
||||
'users' => $users,
|
||||
]);
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'warehouse', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user