| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Request;
- /**
- * 各月制造费用维护
- */
- class CostAccounting extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 各月制造费用维护菜单
- * @return void
- */
- public function getTab()
- {
- // 1. 请求方法验证
- if (!$this->request->isGet()) {
- $this->error('仅支持GET请求');
- }
- // 2. 使用静态变量避免重复创建数组
- static $tabs, $sist;
- if ($tabs === null) {
- $tabs = [
- '1、月度人工数据',
- '2、水电气直接费用',
- '3、水电气分摊费用',
- '4、其他待摊费用',
- '5、车间色度数'
- ];
- $sist = ['胶印车间', '凹丝印车间', '印后车间'];
- }
- // 3. 数据库查询优化
- $months = db('成本_各月水电气')
- ->field('Sys_ny AS year_month')
- ->group('Sys_ny')
- ->order('Sys_ny DESC')
- ->column('Sys_ny');
- // 4. 使用模板构建策略
- $data = [];
- $template = [];
- // 预构建模板
- foreach ($tabs as $tab) {
- $template[$tab] = ($tab === '2、水电气直接费用') ? $sist : $tab;
- }
- // 仅需单次循环赋值
- foreach ($months as $month) {
- $data[$month] = $template;
- }
- $this->success('成功', $data);
- }
- /**
- * 月度车间人工维护
- * @return void
- * @throws \think\db\exception\BindParamException
- * @throws \think\exception\PDOException
- */
- public function ArtificialAdd()
- {
- if($this->request->isPost() === false){
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param)) {
- $this->error('参数错误');
- }
- $data = [];
- foreach ($param as $key => $value) {
- $data[$key] = [
- 'Sys_ny' => $value['sys_ny'],
- '车间' => $value['sist'],
- '一线工资总额' => $value['number'],
- '系数' => 1.2,
- '应发工资' => $value['number'] * 1.2,
- 'Sys_id' => $value['sys_id'],
- 'Sys_rq' => date('Y-m-d H:i:s', time())
- ];
- }
- $sql = db('成本v23_各月人工')->fetchSql(true)->insertAll($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 ArtificialAddList()
- {
- if($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param) || empty($param['Sys_ny'])) {
- $this->error('参数错误');
- }
- $list = db('成本v23_各月人工')
- ->where('Sys_ny', $param['Sys_ny'])
- ->field('Sys_ny, 车间, 一线工资总额, Sys_id as 创建用户, Sys_rq as 创建时间,Mod_rq as 修订时间,UniqID')
- ->select();
- $this->success('成功', $list);
- }
- /**
- * 月度人工维护修改
- * @return void
- * @throws \think\Exception
- * @throws \think\db\exception\BindParamException
- * @throws \think\exception\PDOException
- */
- public function ArtificialEdit()
- {
- if($this->request->isPost() === false){
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param)) {
- $this->error('参数错误');
- }
- $i = 0;
- foreach ($param as $value) {
- $sql = db('成本v23_各月人工')
- ->where('UniqID', $value['UniqID'])
- ->fetchSql(true)
- ->update(['一线工资总额'=>$value['number'],'Mod_rq'=>date('Y-m-d H:i:s', time())]);
- $res = db()->query($sql);
- if ($res === false) {
- $i++;
- }
- }
- if ($i === 0) {
- $this->success('修改成功');
- }else{
- $this->error('修改失败');
- }
- }
- /**
- * 月度人工数据右侧上方列表
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function ArtificialList()
- {
- if (!$this->request->isGet()) {
- $this->error('仅支持GET请求');
- }
- $month = $this->request->param('month');
- if (empty($month)) {
- $this->error('month参数缺失或为空');
- }
- $list = db('成本v23_各月人工')->alias('a')
- ->join('设备_基本资料 b', 'a.车间 = b.使用部门')
- ->join('绩效工资汇总 c', 'a.Sys_ny = c.sys_ny AND c.sczl_jtbh = b.设备编号')
- ->join('成本_各月其他费用 d', 'a.Sys_ny = d.sys_ny','left')
- ->field([
- 'a.Sys_ny' => '年月',
- 'rtrim(a.车间)' => '车间',
- 'SUM(c.个人计件工资) + SUM(c.个人加班工资)' => '人工分摊因子总额',
- 'a.一线工资总额' => '车间实发工资',
- 'd.部门人员工资' => '部门人员工资实发',
- 'd.管理人员工资' => '管理人员工资实发'
- ])
- ->where('a.Sys_ny', $month)
- ->group('a.Sys_ny, a.车间')
- ->select();
- if (empty($list)) {
- $this->success('未找到匹配数据', []);
- }
- $this->success('获取成功', $list);
- }
- /**
- * 月度人工数据下方工单详情
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function ArtificialDetailList()
- {
- if ($this->request->isGet() === false) {
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)) {
- $this->error('参数错误');
- }
- $month = $param['month'];
- $sist = $param['sist'];
- $list = db('工单_质量考核汇总')
- ->alias('a')
- ->join('设备_基本资料 b', 'a.sczl_jtbh = b.设备编号')
- ->join('工单_印件资料 c', 'a.Gy0_gdbh = c.Yj_Gdbh and a.印件及工序 = c.yj_Yjno')
- ->join('工单_工艺资料 d', 'a.Gy0_gdbh = d.Gy0_gdbh and a.印件及工序 = d.Gy0_yjno and a.工序 = d.Gy0_gxh')
- ->field([
- 'a.sys_ny' => '年月',
- 'a.Gy0_gdbh' => '工单编号',
- 'a.印件及工序' => '印件号',
- 'a.工序' => '工序号',
- 'c.yj_yjmc' => '印件名称',
- 'd.Gy0_gxmc' => '工序名称',
- 'a.印件工序产量' => '班组车头产量',
- 'd.工价系数' => '工序难度系数',
- 'SUM(a.CjsJe)' => '计件工资',
- 'rtrim(b.使用部门)' => '车间名称',
- ])
- ->where('a.Sys_ny', $month)
- ->where('b.使用部门', $sist)
- ->group('a.Sys_ny, a.Gy0_gdbh,a.印件及工序,a.印件及工序')
- ->order('a.Gy0_gdbh')
- ->select();
- if (empty($list)) {
- $this->success('未找到数据');
- }else{
- $this->success('成功', $list);
- }
- }
- /**
- * 水电气直接费用右侧列表
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function shuidianqiList()
- {
- if ($this->request->isGet() === false) {
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)) {
- $this->error('参数错误');
- }
- $month = $param['month'];
- $sist = $param['sist'];
- $list = db('成本_各月水电气')
- ->field('rtrim(部门名称) as 部门名称,rtrim(设备编号) as 设备编号,rtrim(科目名称) as 设备名称,rtrim(耗电量) as 耗电量,
- rtrim(单位电价) as 单位电价,rtrim(耗气量) as 耗气量,rtrim(单位气价) as 单位气价,rtrim(Sys_id) as 创建用户,Sys_rq as 创建时间,UniqID,耗电量*单位电价 as 直接费用合计')
- ->where('Sys_ny', $month)
- ->where('部门名称', $sist)
- ->where('费用类型', '直接')
- ->group('Sys_ny, Sys_rq, UniqID')
- ->select();
- if (empty($list)) {
- $this->success('未找到数据');
- }else{
- $this->success('成功', $list);
- }
- }
- /**
- * 水电气下方工单详情
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function shuidianqiDetailList()
- {
- 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);
- $machine = $param['machine'];
- $list = db('设备_产量计酬')
- ->alias('a')
- ->join('工单_印件资料 b', 'a.sczl_gdbh = b.Yj_Gdbh and a.sczl_yjno = b.yj_Yjno')
- ->field('a.sczl_gdbh as 工单编号,b.yj_yjmc as 印件名称,a.sczl_yjno as 印件号,a.sczl_gxh as 工序号,
- sum(a.sczl_cl)*a.sczl_ls as 班组车头产量,sum(a.sczl_设备运行工时) as 占用机时')
- ->where('a.sczl_rq','like', '%'.$month.'%')
- ->where('a.sczl_jtbh', $machine)
- ->group('a.sczl_gdbh, a.sczl_yjno, a.sczl_gxh')
- ->select();
- if (empty($list)) {
- $this->success('未找到数据');
- }
- foreach ($list as $k => $v) {
- $list[$k]['计件产量'] = $v['班组车头产量'];
- $list[$k]['水电气分摊因子'] = $v['占用机时'];
- $list[$k]['年月'] = $param['month'];
- }
- $this->success('成功', $list);
- }
- /**
- * 水电气分摊费用
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function shuidianqifentanList()
- {
- if ($this->request->isGet() === false) {
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)) {
- $this->error('参数错误');
- }
- $month = $param['month'];
- $list = db('成本_各月水电气')
- ->field('rtrim(部门名称) as 部门名称,rtrim(设备编号) as 设备编号,rtrim(科目名称) as 设备名称,rtrim(耗电量) as 耗电量,
- rtrim(单位电价) as 单位电价,rtrim(耗气量) as 耗气量,rtrim(单位气价) as 单位气价,rtrim(Sys_id) as 创建用户,Sys_rq as 创建时间,UniqID,耗电量*单位电价 as 直接费用合计')
- ->where('Sys_ny', $month)
- ->where('费用类型', '分摊')
- ->group('Sys_ny, Sys_rq, UniqID')
- ->select();
- if (empty($list)) {
- $this->success('未找到数据');
- }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 ChromaticityAdd()
- {
- if ($this->request->isGet() === false) {
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)) {
- $this->error('参数错误');
- }
- $list = db('绩效工资汇总')
- ->alias('a')
- ->join('工单_工艺资料 b','a.sczl_gdbh = b.Gy0_gdbh and a.sczl_yjno = b.Gy0_yjno and a.sczl_gxh = b.Gy0_gxh')
- ->join('设备_基本资料 c','a.sczl_jtbh = c.设备编号','LEFT')
- ->join('工单_印件资料 d','a.sczl_gdbh = d.Yj_Gdbh and a.sczl_yjno = d.yj_Yjno')
- ->field('a.sczl_gdbh as 工单编号,a.sczl_yjno as 印件号,a.sczl_gxh as 工序号,sum(a.班组车头产量) as 班组车头产量,b.Gy0_gxmc as 工序名称,
- a.sczl_ms as 墨色数,c.使用部门,b.印刷方式,b.版距,b.工价系数,a.sczl_jtbh,d.yj_yjmc as 印件名称,sum(a.车头产量占用机时) as 占用机时,a.sys_rq as 年月,
- a.工序难度系数,sum(a.班组换算产量) as 班组换算产量,a.千件工价')
- ->where('a.sys_ny', $param['month'])
- ->group('a.sczl_gdbh,a.sczl_yjno,a.sczl_gxh,a.sczl_jtbh')
- ->select();
- $data = [];
- foreach ($list as $k => $v) {
- if ($v['版距'] === '0.0'){
- $list[$k]['版距'] = 1000;
- }
- if ($v['墨色数'] === '0.00'){
- $list[$k]['墨色数'] = 1;
- }
- if (strpos($v['工序名称'],'切废')){
- $list[$k]['墨色数'] = 0.2;
- }
- $chanliang = $v['班组车头产量']*$v['工序难度系数'] + $v['班组换算产量'];
- $data[] = [
- '车间名称' => $v['使用部门'],
- 'sys_ny' => $param['month'],
- 'sczl_gdbh' => $v['工单编号'],
- '印件名称' => $v['印件名称'],
- 'sczl_yjno' => $v['印件号'],
- 'sczl_gxh' => $v['工序号'],
- '工序名称' => $v['工序名称'],
- 'sczl_jtbh' => $v['sczl_jtbh'],
- '卷张换算系数' => $list[$k]['版距']/1000,
- '占用机时' => $v['占用机时'],
- '班组车头产量' => $v['班组车头产量'],
- 'sczl_ms' => $list[$k]['墨色数'],
- '工序难度系数' => $v['工序难度系数'],
- '班组换算产量' => $v['班组换算产量'],
- '千件工价' => $v['千件工价'],
- '计件产量' => $chanliang,
- '水电分摊因子' => $v['占用机时'],
- '材料分摊因子' => $chanliang,
- '人工分摊因子' => ($chanliang/1000)*$v['千件工价'],
- 'Sys_id' => $param['sys_id'],
- 'Sys_rq' => date('Y-m-d H:i:s', time())
- ];
- }
- $sql = db('成本v23_月度成本明细')->fetchSql(true)->insertAll($data);
- $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 ChromaticityDetailAdd()
- {
- 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);
- $list = db('设备_产量计酬')
- ->alias('a')
- ->join('设备_基本资料 b','a.sczl_jtbh = b.设备编号')
- ->join('工单_工艺资料 c','a.sczl_gdbh = c.Gy0_gdbh and a.sczl_yjno = c.Gy0_yjno and a.sczl_gxh = c.Gy0_gxh')
- ->field('a.sczl_gdbh,a.sczl_yjno,a.sczl_gxh,a.sczl_jtbh,a.sczl_gxmc,sum(a.sczl_cl) as 产量,a.sczl_jtbh,a.sczl_ms,b.使用部门,
- sum(a.sczl_设备运行工时) as 通电工时,a.sczl_dedh,c.Gy0_gxmc')
- ->where('a.sczl_rq','like', $month.'%')
- ->group('a.sczl_gdbh,a.sczl_yjno,a.sczl_gxh,a.sczl_jtbh')
- ->select();
- if (empty($list)) {
- $this->error('没找到生产数据');
- }
- $data = [];
- foreach ($list as $k => $v) {
- if ($v['sczl_ms'] === '0.00'){
- $list[$k]['sczl_ms'] = 1;
- }
- if (strpos($v['Gy0_gxmc'],'切废') !== false){
- $list[$k]['sczl_ms'] = 0.2;
- }
- $data[] = [
- '年月' => $param['month'],
- 'sczl_gdbh' => $v['sczl_gdbh'],
- 'sczl_yjno' => $v['sczl_yjno'],
- 'sczl_gxh' => $v['sczl_gxh'],
- 'sczl_jtbh' => $v['sczl_jtbh'],
- 'sczl_gxmc' => $v['sczl_gxmc'],
- 'sczl_ms' => $v['sczl_ms'],
- 'sczl_dedh' => $v['sczl_dedh'],
- '通电时间' => $v['通电工时'],
- 'sczl_cl' => $v['产量'],
- '部门' => $v['使用部门'],
- 'Sys_ID' => $param['sys_id'],
- 'Sys_Rq' => date('Y-m-d H:i:s', time())
- ];
- }
- if (db('成本_各月色度数')->where('年月',$param['month'])->count() !== 0) {
- db('成本_各月色度数')->where('年月',$param['month'])->delete();
- }
- $sql = db('成本_各月色度数')->fetchSql(true)->insertAll($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 ChromaticityDetailList()
- {
- if ($this->request->isGet() === false) {
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)) {
- $this->error('参数错误');
- }
- // 执行统计查询
- $stats = db('成本_各月色度数')
- ->field([
- 'rtrim(部门) AS workshop',
- 'SUM(sczl_cl * IF(sczl_ms=0, 1, sczl_ms)) AS total'
- ])
- ->where('部门', '<>', '') // 过滤空车间数据
- ->where('sczl_cl', '>', 0) // 过滤无效产量
- ->where('年月', $param['month'])
- ->group('部门')
- ->select();
- // 构造中文返回结果
- $result = [];
- foreach ($stats as $item) {
- $result[] = [
- '年月' => $param['month'],
- '车间' => $item['workshop'],
- '色度数' => number_format($item['total'], 2)
- ];
- }
- $this->success('成功', $result);
- }
- /**
- * 车间色度数详情列表
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function MonochromaticDetailList()
- {
- if ($this->request->isGet() === false) {
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)) {
- $this->error('参数错误');
- }
- $list = db('成本_各月色度数')
- ->where('年月', $param['month'])
- ->where('部门', $param['sist'])
- ->order('sczl_gdbh')
- ->select();
- $this->success('成功', $list);
- }
- /**
- * 车间成本核算汇总
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function SummaryCostAccountingList()
- {
- if ($this->request->isGet() === false) {
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)) {
- $this->error('参数错误');
- }
- $list = db('成本v23_月度成本明细')
- ->where('车间名称', $param['sist'])
- ->where('sys_ny', $param['month'])
- ->order('sczl_gdbh')
- ->select();
- if (empty($list)) {
- $this->error('未找到数据');
- }else{
- $this->success('成功', $list);
- }
- }
- /**
- * 创建各月水电气分摊
- * @return void
- * @throws \think\db\exception\BindParamException
- * @throws \think\exception\PDOException
- */
- public function UtilitiesAdd()
- {
- if ($this->request->isPost() === false) {
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param)) {
- $this->error('参数错误');
- }
- $data = [];
- foreach ($param as $k => $v) {
- $data[] = [
- 'Sys_ny' => $v['sys_ny'],
- '部门名称' => $v['sist'],
- '费用类型' => '分摊',
- '科目名称' => $v['科目名称'],
- '耗电量' => $v['耗电量']??0,
- '单位电价' => $v['单位电价'],
- '耗气量' => $v['耗气量']??0,
- '单位气价' => $v['单位气价'],
- 'Sys_id' => $v['sys_id'],
- 'Sys_rq' => date('Y-m-d H:i:s', time())
- ];
- }
- $result = db('成本_各月水电气')->where('Sys_ny', $data[0]['Sys_ny'])->where('费用类型','分摊')->delete();
- $sql = db('成本_各月水电气')->fetchSql(true)->insertAll($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 UtilitiesList()
- {
- if($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)) {
- $this->error('参数错误');
- }
- $list = db('成本_各月水电气')
- ->field('rtrim(部门名称) as 部门名称,rtrim(科目名称) as 科目名称,耗电量,单位电价,耗气量,单位气价')
- ->where('费用类型', '分摊')
- ->where('Sys_ny', $param['month'])
- ->group('部门名称,科目名称')
- ->select();
- if (empty($list)) {
- $list = db('成本_各月水电气')
- ->field('rtrim(部门名称) as 部门名称,rtrim(科目名称) as 科目名称')
- ->where('费用类型', '分摊')
- ->group('部门名称,科目名称')
- ->select();
- }
- foreach ($list as $k => $v) {
- $list[$k]['年月'] = $param['month'];
- }
- $this->success('成功', $list);
- }
- /**
- * 成本汇总左侧列表
- * @return void
- */
- public function getSummaryTab()
- {
- if ($this->request->isGet() === false) {
- $this->error('请求错误');
- }
- $months = db('成本v23_月度成本明细')
- ->field('sys_ny AS year_month')
- ->group('Sys_ny')
- ->order('Sys_ny DESC')
- ->column('Sys_ny');
- $sist = ['胶印车间','凹丝印车间','印后车间','检验车间'];
- $data = [];
- foreach ($months as $month) {
- $data[$month] = $sist;
- }
- $this->success('成功', $data);
- }
- //计算每个车间色度数
- private function CountSistChromaticity($month,$sist)
- {
- $data = db('成本v23_月度成本明细')
- ->where('sys_ny', $month)
- ->where('车间名称', $sist)
- ->group('车间名称')
- ->value('班组车头产量*sczl_ms as 色度数');
- return $data;
- }
- //计算每个机台色度数
- private function CountMachineChromatic($month,$sist)
- {
- $data = db('成本v23_月度成本明细')
- ->where('sys_ny', $month)
- ->where('车间名称', $sist)
- ->group('sczl_jtbh')
- ->value('班组车头产量*sczl_ms as 色度数');
- return $data;
- }
- //水电气分摊费用下方明细列表
- 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) {
- $this->error('请求错误');
- }
- $param = $this->request->param();
- 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;
- // }
- }
|