|
|
@@ -122,6 +122,26 @@ class CostAccounting extends Api
|
|
|
->where('Sys_ny', $param['Sys_ny'])
|
|
|
->field('Sys_ny, 车间, 一线工资总额, Sys_id as 创建用户, Sys_rq as 创建时间,Mod_rq as 修订时间,UniqID')
|
|
|
->select();
|
|
|
+ if (empty($list)) {
|
|
|
+ $list = [
|
|
|
+ [
|
|
|
+ 'Sys_ny' => $param['Sys_ny'],
|
|
|
+ '车间' => '胶印车间',
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'Sys_ny' => $param['Sys_ny'],
|
|
|
+ '车间' => '凹丝印车间',
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'Sys_ny' => $param['Sys_ny'],
|
|
|
+ '车间' => '印后车间',
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'Sys_ny' => $param['Sys_ny'],
|
|
|
+ '车间' => '检验车间',
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ }
|
|
|
$this->success('成功', $list);
|
|
|
}
|
|
|
|
|
|
@@ -509,10 +529,10 @@ class CostAccounting extends Api
|
|
|
}
|
|
|
// 执行统计查询
|
|
|
$stats = db('成本_各月色度数')
|
|
|
- ->field([
|
|
|
- 'rtrim(部门) AS workshop',
|
|
|
- 'SUM(sczl_cl * IF(sczl_ms=0, 1, sczl_ms)) AS total'
|
|
|
- ])
|
|
|
+ ->field([
|
|
|
+ 'rtrim(部门) AS workshop',
|
|
|
+ 'SUM(sczl_cl * IF(sczl_ms=0, 1, sczl_ms)) AS total'
|
|
|
+ ])
|
|
|
->where('部门', '<>', '') // 过滤空车间数据
|
|
|
->where('sczl_cl', '>', 0) // 过滤无效产量
|
|
|
->where('年月', $param['month'])
|
|
|
@@ -706,33 +726,83 @@ class CostAccounting extends Api
|
|
|
}
|
|
|
|
|
|
//水电气分摊费用下方明细列表
|
|
|
-// public function shuidianqiMachineDetailList()
|
|
|
-// {
|
|
|
-// if ($this->request->isGet() === false) {
|
|
|
-// $this->error('请求错误');
|
|
|
-// }
|
|
|
-// $param = $this->request->param();
|
|
|
-// if (empty($param)) {
|
|
|
-// $this->error('参数错误');
|
|
|
-// }
|
|
|
-// $sist = ['胶印车间','凹丝印车间','印后车间','检验车间'];
|
|
|
-// if (strpos($param['sist'],'车间') === false) {
|
|
|
-// $number = db('成本_各月水电气')
|
|
|
-// ->where('Sys_ny', $param['month'])
|
|
|
-// ->where('部门名称', $param['sist'])
|
|
|
-// ->where('费用类型', '分摊')
|
|
|
-// ->value('');
|
|
|
-// }else{
|
|
|
-// $machineList = db('设备_基本资料')
|
|
|
-// ->where('使用部门', $param['sist'])
|
|
|
-// ->where('sys_sbID', '<>', '')
|
|
|
-// ->order('设备编号')
|
|
|
-// ->column('设备编号');
|
|
|
-// }
|
|
|
-//
|
|
|
-// }
|
|
|
-
|
|
|
- //其他待摊费用
|
|
|
+ public function shuidianqiMachineDetailList()
|
|
|
+ {
|
|
|
+ if ($this->request->isGet() === false) {
|
|
|
+ $this->error('请求错误');
|
|
|
+ }
|
|
|
+ $param = $this->request->param();
|
|
|
+ if (empty($param)) {
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
+ $sist = ['胶印车间','凹丝印车间','印后车间','检验车间'];
|
|
|
+ if (strpos($param['sist'],'车间') === false) {
|
|
|
+ $number = db('成本_各月水电气')
|
|
|
+ ->where('Sys_ny', $param['month'])
|
|
|
+ ->where('部门名称', $param['sist'])
|
|
|
+ ->where('费用类型', '分摊')
|
|
|
+ ->value('');
|
|
|
+ }else{
|
|
|
+ $machineList = db('设备_基本资料')
|
|
|
+ ->where('使用部门', $param['sist'])
|
|
|
+ ->where('sys_sbID', '<>', '')
|
|
|
+ ->order('设备编号')
|
|
|
+ ->column('设备编号');
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 其他待摊费用
|
|
|
+ * @return void
|
|
|
+ * @throws \think\db\exception\BindParamException
|
|
|
+ * @throws \think\exception\PDOException
|
|
|
+ */
|
|
|
+ public function PrepaidExpensesListEdit()
|
|
|
+ {
|
|
|
+ if ($this->request->isPost() === false) {
|
|
|
+ $this->error('请求错误');
|
|
|
+ }
|
|
|
+ $param = Request::instance()->post();
|
|
|
+ if (empty($param)) {
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
+ $data = [
|
|
|
+ 'sys_ny' => $param['month'],
|
|
|
+ '部门人员工资' => $param['salary1'],
|
|
|
+ '管理人员工资' => $param['salary2'],
|
|
|
+ '场地租金' => $param['rental'],
|
|
|
+ '待摊折旧' => $param['depreciation'],
|
|
|
+ '工资成本占比' => $param['proportion'],
|
|
|
+ '其他' => $param['rest'],
|
|
|
+ '后勤人员工资' => $param['profit'],
|
|
|
+ 'sys_id' => $param['sys_id'],
|
|
|
+ ];
|
|
|
+ $result = db('成本_各月其他费用')->where('sys_ny', $param['month'])->count();
|
|
|
+ if ($result > 0) {
|
|
|
+ $data['mod_rq'] = date('Y-m-d H:i:s', time());
|
|
|
+ $sql = db('成本_各月其他费用')->where('sys_ny', $param['month'])->fetchSql(true)->update($data);
|
|
|
+ }else{
|
|
|
+ $data['sys_rq'] = date('Y-m-d H:i:s', time());
|
|
|
+ $sql = db('成本_各月其他费用')
|
|
|
+ ->fetchSql(true)
|
|
|
+ ->insert($data);
|
|
|
+ }
|
|
|
+ $res = db()->query($sql);
|
|
|
+ if ($res !== false) {
|
|
|
+ $this->success('成功');
|
|
|
+ }else{
|
|
|
+ $this->error('失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 其他待摊费用列表
|
|
|
+ * @return void
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ */
|
|
|
public function PrepaidExpensesList()
|
|
|
{
|
|
|
if ($this->request->isGet() === false) {
|
|
|
@@ -742,6 +812,234 @@ class CostAccounting extends Api
|
|
|
if (empty($param)) {
|
|
|
$this->error('参数错误');
|
|
|
}
|
|
|
+ $list = db('成本_各月其他费用')
|
|
|
+ ->where('sys_ny', $param['month'])
|
|
|
+ ->field('sys_ny as 年月,部门人员工资,管理人员工资,场地租金,待摊折旧,工资成本占比,其他,后勤人员工资,sys_id as 创建用户,sys_rq as 创建时间,mod_rq as 修改时间,UniqID')
|
|
|
+ ->find();
|
|
|
+ if (empty($list)) {
|
|
|
+ $this->error('未找到数据');
|
|
|
+ }else{
|
|
|
+ $this->success('成功', $list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 参考其他费用参考月份
|
|
|
+ * @return void
|
|
|
+ * @throws \think\db\exception\BindParamException
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ * @throws \think\exception\PDOException
|
|
|
+ */
|
|
|
+ public function PrepaidExpensesDetailCopy()
|
|
|
+ {
|
|
|
+ if ($this->request->isGet() === false) {
|
|
|
+ $this->error('请求错误');
|
|
|
+ }
|
|
|
+ $param = $this->request->param();
|
|
|
+ if (empty($param)) {
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
+ $formMonth = $param['formMonth'];
|
|
|
+ $toMonth = $param['toMonth'];
|
|
|
+ $list = db('成本_各月其他费用')
|
|
|
+ ->where('sys_ny', $formMonth)
|
|
|
+ ->field('管理人员工资,场地租金,待摊折旧,工资成本占比,后勤人员工资')
|
|
|
+ ->find();
|
|
|
+ $list['sys_ny'] = $toMonth;
|
|
|
+ $list['sys_id'] = $param['sys_id'];
|
|
|
+ $list['sys_rq'] = date('Y-m-d H:i:s', time());
|
|
|
+ $sql = db('成本_各月其他费用')
|
|
|
+ ->fetchSql(true)
|
|
|
+ ->insert($list);
|
|
|
+ $res = db()->query($sql);
|
|
|
+ if ($res !== false) {
|
|
|
+ $this->success('成功');
|
|
|
+ }else{
|
|
|
+ $this->error('失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 各月水电气直接费用创建
|
|
|
+ * @return void
|
|
|
+ * @throws \think\db\exception\BindParamException
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ * @throws \think\exception\PDOException
|
|
|
+ */
|
|
|
+ public function shuidianqiDetailAdd()
|
|
|
+ {
|
|
|
+ if ($this->request->isGet() === false) {
|
|
|
+ $this->error('请求错误');
|
|
|
+ }
|
|
|
+ $param = $this->request->param();
|
|
|
+ if (empty($param)) {
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
+ $month = substr($param['month'], 0, 4) . '-' . substr($param['month'], 4, 2);
|
|
|
+ $sist = ['胶印车间','凹丝印车间','印后车间'];
|
|
|
+ $list = db('设备_产量计酬')
|
|
|
+ ->alias('a')
|
|
|
+ ->join('设备_基本资料 b', 'a.sczl_jtbh = b.设备编号')
|
|
|
+ ->where('a.sczl_rq', 'like', $month . '%')
|
|
|
+ ->where('b.sys_sbID','<>','')
|
|
|
+ ->where('b.使用部门','in',$sist)
|
|
|
+ ->field('a.sczl_jtbh,sum(a.sczl_设备运行工时) as 通电工时,b.使用部门,rtrim(b.设备名称) as 设备名称')
|
|
|
+ ->order('b.使用部门,a.sczl_jtbh')
|
|
|
+ ->group('a.sczl_jtbh')
|
|
|
+ ->select();
|
|
|
+ $data = [];
|
|
|
+ foreach ($list as $k => $v) {
|
|
|
+ $data[] = [
|
|
|
+ 'Sys_ny' => $param['month'],
|
|
|
+ '部门名称' => $v['使用部门'],
|
|
|
+ '费用类型' => '直接',
|
|
|
+ '设备编号' => $v['sczl_jtbh'],
|
|
|
+ '科目名称' => $v['设备名称'],
|
|
|
+ '耗电量' => $v['通电工时'],
|
|
|
+ '单位电价' => 0.69,
|
|
|
+ 'Sys_id' => $param['sys_id'],
|
|
|
+ 'Sys_rq' => date('Y-m-d H:i:s', time()),
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $sql = db('成本_各月水电气')->fetchSql(true)->insertAll($data);
|
|
|
+ $res = db()->query($sql);
|
|
|
+ if ($res !== false) {
|
|
|
+ $this->success('成功');
|
|
|
+ }else{
|
|
|
+ $this->error('失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //计算成本
|
|
|
+ public function CostCalculation()
|
|
|
+ {
|
|
|
+ if ($this->request->isGet() === false) {
|
|
|
+ $this->error('请求错误');
|
|
|
+ }
|
|
|
+ $param = $this->request->param();
|
|
|
+ if (empty($param)) {
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
+ //查询工单数据
|
|
|
+ $list = db('成本v23_月度成本明细')
|
|
|
+ ->field('车间名称,sys_ny as 年月,sczl_gdbh as 工单编号,sczl_yjno as 印件号,sczl_gxh as 工序号,工序名称,sczl_jtbh as jtbh,
|
|
|
+ 占用机时,计件产量,sczl_ms as 墨色数,Uniqid,计件产量*sczl_ms as 色度数')
|
|
|
+ ->where('sys_ny', $param['month'])
|
|
|
+ ->whereNotNull('车间名称')
|
|
|
+ ->select();
|
|
|
+ //查询整月全车间色度数之和
|
|
|
+ $ChromaticityCount = db('成本v23_月度成本明细')
|
|
|
+ ->where('sys_ny', $param['month'])
|
|
|
+ ->whereNotNull('车间名称')
|
|
|
+ ->column('sum(计件产量*sczl_ms)');
|
|
|
+ //查询整月各车间色度数
|
|
|
+ $MachineChromaticityCount = db('成本v23_月度成本明细')
|
|
|
+ ->where('sys_ny', $param['month'])
|
|
|
+ ->whereNotNull('车间名称')
|
|
|
+ ->group('车间名称')
|
|
|
+ ->column('sum(计件产量*sczl_ms)');
|
|
|
+ //计算车间水电气
|
|
|
+ $res = $this->ApportionmentOne($param['month']);
|
|
|
+ halt($res);
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|
|
|
+ //计算水电气分摊费用
|
|
|
+ protected function ApportionmentOne($month)
|
|
|
+ {
|
|
|
+ $list = db('成本_各月水电气')
|
|
|
+ ->where('Sys_ny', $month)
|
|
|
+ ->where('费用类型','like','%分摊%')
|
|
|
+ ->select();
|
|
|
+ foreach ($list as $k => $v) {
|
|
|
+ if ($v['科目名称'] == '待分摊总额') {
|
|
|
+ $money = $v['耗电量'] * $v['单位电价'];
|
|
|
+ $data = $this->MachineTime($v['部门名称'],$month);
|
|
|
+ foreach ($data['machine'] as $k1 => $v1) {
|
|
|
+ $data['machine'][$k1]['分摊水电'] = round($money*($v1['占用机时']/$data['sist']),2) ;
|
|
|
+ }
|
|
|
+ }elseif (strpos($v['科目名称'],'废气处理') !== false) {
|
|
|
+ $electricityMoney = $v['耗电量'] * $v['单位电价'];
|
|
|
+ $gasMoney = $v['耗气量'] * $v['单位气价'];
|
|
|
+ $data = $this->MachineTime('03、卷凹机组',$month);
|
|
|
+ foreach ($data['machine'] as $k1 => $v1) {
|
|
|
+ $data['machine'][$k1]['分摊水电'] = round($electricityMoney*($v1['占用机时']/$data['sist']),2) ;
|
|
|
+ $data['machine'][$k1]['废气处理'] = round($gasMoney*($v1['占用机时']/$data['sist']),2) ;
|
|
|
+ }
|
|
|
+ }elseif (strpos($v['科目名称'],'锅炉') !== false && strpos($v['科目名称'],'热水锅炉') === false) {
|
|
|
+ $electricityMoney = $v['耗电量'] * $v['单位电价'];
|
|
|
+ $gasMoney = $v['耗气量'] * $v['单位气价'];
|
|
|
+ $data = $this->MachineTime('03、卷凹机组',$month);
|
|
|
+ foreach ($data['machine'] as $k1 => $v1) {
|
|
|
+ $data['machine'][$k1]['分摊水电'] = round($electricityMoney*($v1['占用机时']/$data['sist']),2) ;
|
|
|
+ $data['machine'][$k1]['锅炉'] = round($gasMoney*($v1['占用机时']/$data['sist']),2) ;
|
|
|
+ }
|
|
|
+ }elseif (strpos($v['科目名称'],'空压机A') !== false) {
|
|
|
+ $money = $v['耗电量'] * $v['单位电价'];
|
|
|
+ $sistList = ['凹丝印车间','胶印车间','印后车间','检验车间'];
|
|
|
+ $data = $this->MachineTime($sistList,$month);
|
|
|
+ foreach ($data['machine'] as $k1 => $v1) {
|
|
|
+ $data['machine'][$k1]['空压机A'] = round($money*($v1['占用机时']/$data['sist']),2) ;
|
|
|
+ }
|
|
|
+ }elseif (strpos($v['科目名称'],'空压机B') !== false) {
|
|
|
+ $money = $v['耗电量'] * $v['单位电价'];
|
|
|
+ $sistList = ['凹丝印车间','胶印车间','印后车间','检验车间'];
|
|
|
+ $data = $this->MachineTime($sistList,$month);
|
|
|
+ foreach ($data['machine'] as $k1 => $v1) {
|
|
|
+ $data['machine'][$k1]['空压机B'] = round($money*($v1['占用机时']/$data['sist']),2) ;
|
|
|
+ }
|
|
|
+ }elseif (strpos($v['科目名称'],'热水锅炉') !== false){
|
|
|
+ $money = $v['耗电量'] * $v['单位电价'];
|
|
|
+ $sistList = ['凹丝印车间','胶印车间','印后车间','检验车间'];
|
|
|
+ $data = $this->MachineTime($sistList,$month);
|
|
|
+ foreach ($data['machine'] as $k1 => $v1) {
|
|
|
+ $data['machine'][$k1]['热水锅炉'] = round($money*($v1['占用机时']/$data['sist']),2) ;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询车间全部机台通电机时数据
|
|
|
+ protected function MachineTime($sist,$month)
|
|
|
+ {
|
|
|
+ $where['a.sys_ny'] = $month;
|
|
|
+ $where['b.sys_sbID'] = ['<>',''];
|
|
|
+ if (is_array($sist)) {
|
|
|
+ $where['a.车间名称'] = ['in',$sist];
|
|
|
+ }else{
|
|
|
+ if (strpos($sist,'机组') !== false) {
|
|
|
+ $where['b.设备编组'] = $sist;
|
|
|
+ }elseif (strpos($sist,'车间') !== false) {
|
|
|
+ $where['a.车间名称'] = $sist;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //查询各个工单工艺通电时间
|
|
|
+ $machine = db('成本v23_月度成本明细')
|
|
|
+ ->alias('a')
|
|
|
+ ->join('设备_基本资料 b', 'a.sczl_jtbh = b.设备编号','left')
|
|
|
+ ->field('a.sczl_gdbh as 工单编号,a.sczl_yjno as 印件号,a.sczl_gxh as 工序号,a.sczl_jtbh as 机台编号,a.占用机时,a.Uniqid')
|
|
|
+ ->where($where)
|
|
|
+ ->select();
|
|
|
+ //查询各个车间通电总时长
|
|
|
+ $sist = db('成本v23_月度成本明细')
|
|
|
+ ->alias('a')
|
|
|
+ ->join('设备_基本资料 b', 'a.sczl_jtbh = b.设备编号','left')
|
|
|
+ ->where($where)
|
|
|
+ ->value('sum(a.占用机时) as 占用机时');
|
|
|
+ $data = [
|
|
|
+ 'machine' => $machine,
|
|
|
+ 'sist' => $sist
|
|
|
+ ];
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
}
|