CostAccounting.php 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Request;
  5. /**
  6. * 各月制造费用维护
  7. */
  8. class CostAccounting extends Api
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. /**
  13. * 各月制造费用维护菜单
  14. * @return void
  15. */
  16. public function getTab()
  17. {
  18. // 1. 请求方法验证
  19. if (!$this->request->isGet()) {
  20. $this->error('仅支持GET请求');
  21. }
  22. // 2. 使用静态变量避免重复创建数组
  23. static $tabs, $sist;
  24. if ($tabs === null) {
  25. $tabs = [
  26. '1、月度人工数据',
  27. '2、水电气直接费用',
  28. '3、水电气分摊费用',
  29. '4、其他待摊费用',
  30. '5、车间色度数'
  31. ];
  32. $sist = ['胶印车间', '凹丝印车间', '印后车间'];
  33. }
  34. // 3. 数据库查询优化
  35. $months = db('成本_各月水电气')
  36. ->field('Sys_ny AS year_month')
  37. ->group('Sys_ny')
  38. ->order('Sys_ny DESC')
  39. ->column('Sys_ny');
  40. // 4. 使用模板构建策略
  41. $data = [];
  42. $template = [];
  43. // 预构建模板
  44. foreach ($tabs as $tab) {
  45. $template[$tab] = ($tab === '2、水电气直接费用') ? $sist : $tab;
  46. }
  47. // 仅需单次循环赋值
  48. foreach ($months as $month) {
  49. $data[$month] = $template;
  50. }
  51. $this->success('成功', $data);
  52. }
  53. /**
  54. * 月度车间人工维护
  55. * @return void
  56. * @throws \think\db\exception\BindParamException
  57. * @throws \think\exception\PDOException
  58. */
  59. public function ArtificialAdd()
  60. {
  61. if($this->request->isPost() === false){
  62. $this->error('请求错误');
  63. }
  64. $param = Request::instance()->post();
  65. if (empty($param)) {
  66. $this->error('参数错误');
  67. }
  68. $data = [];
  69. foreach ($param as $key => $value) {
  70. $data[$key] = [
  71. 'Sys_ny' => $value['sys_ny'],
  72. '车间' => $value['sist'],
  73. '一线工资总额' => $value['number'],
  74. '系数' => 1.2,
  75. '应发工资' => $value['number'] * 1.2,
  76. 'Sys_id' => $value['sys_id'],
  77. 'Sys_rq' => date('Y-m-d H:i:s', time())
  78. ];
  79. }
  80. $sql = db('成本v23_各月人工')->fetchSql(true)->insertAll($data);
  81. $res = db()->query($sql);
  82. if ($res !== false) {
  83. $this->success('新增成功');
  84. }else{
  85. $this->error('添加失败');
  86. }
  87. }
  88. /**
  89. * 月度人工维护列表
  90. * @return void
  91. * @throws \think\db\exception\DataNotFoundException
  92. * @throws \think\db\exception\ModelNotFoundException
  93. * @throws \think\exception\DbException
  94. */
  95. public function ArtificialAddList()
  96. {
  97. if($this->request->isGet() === false){
  98. $this->error('请求错误');
  99. }
  100. $param = $this->request->param();
  101. if (empty($param) || empty($param['Sys_ny'])) {
  102. $this->error('参数错误');
  103. }
  104. $list = db('成本v23_各月人工')
  105. ->where('Sys_ny', $param['Sys_ny'])
  106. ->field('Sys_ny, 车间, 一线工资总额, Sys_id as 创建用户, Sys_rq as 创建时间,Mod_rq as 修订时间,UniqID')
  107. ->select();
  108. if (empty($list)) {
  109. $list = [
  110. [
  111. 'Sys_ny' => $param['Sys_ny'],
  112. '车间' => '胶印车间',
  113. ],
  114. [
  115. 'Sys_ny' => $param['Sys_ny'],
  116. '车间' => '凹丝印车间',
  117. ],
  118. [
  119. 'Sys_ny' => $param['Sys_ny'],
  120. '车间' => '印后车间',
  121. ],
  122. [
  123. 'Sys_ny' => $param['Sys_ny'],
  124. '车间' => '检验车间',
  125. ]
  126. ];
  127. }
  128. $this->success('成功', $list);
  129. }
  130. /**
  131. * 月度人工维护修改
  132. * @return void
  133. * @throws \think\Exception
  134. * @throws \think\db\exception\BindParamException
  135. * @throws \think\exception\PDOException
  136. */
  137. public function ArtificialEdit()
  138. {
  139. if($this->request->isPost() === false){
  140. $this->error('请求错误');
  141. }
  142. $param = Request::instance()->post();
  143. if (empty($param)) {
  144. $this->error('参数错误');
  145. }
  146. $i = 0;
  147. foreach ($param as $value) {
  148. $sql = db('成本v23_各月人工')
  149. ->where('UniqID', $value['UniqID'])
  150. ->fetchSql(true)
  151. ->update(['一线工资总额'=>$value['number'],'Mod_rq'=>date('Y-m-d H:i:s', time())]);
  152. $res = db()->query($sql);
  153. if ($res === false) {
  154. $i++;
  155. }
  156. }
  157. if ($i === 0) {
  158. $this->success('修改成功');
  159. }else{
  160. $this->error('修改失败');
  161. }
  162. }
  163. /**
  164. * 月度人工数据右侧上方列表
  165. * @return void
  166. * @throws \think\db\exception\DataNotFoundException
  167. * @throws \think\db\exception\ModelNotFoundException
  168. * @throws \think\exception\DbException
  169. */
  170. public function ArtificialList()
  171. {
  172. if (!$this->request->isGet()) {
  173. $this->error('仅支持GET请求');
  174. }
  175. $month = $this->request->param('month');
  176. if (empty($month)) {
  177. $this->error('month参数缺失或为空');
  178. }
  179. $list = db('成本v23_各月人工')->alias('a')
  180. ->join('设备_基本资料 b', 'a.车间 = b.使用部门')
  181. ->join('绩效工资汇总 c', 'a.Sys_ny = c.sys_ny AND c.sczl_jtbh = b.设备编号')
  182. ->join('成本_各月其他费用 d', 'a.Sys_ny = d.sys_ny','left')
  183. ->field([
  184. 'a.Sys_ny' => '年月',
  185. 'rtrim(a.车间)' => '车间',
  186. 'SUM(c.个人计件工资) + SUM(c.个人加班工资)' => '人工分摊因子总额',
  187. 'a.一线工资总额' => '车间实发工资',
  188. 'd.部门人员工资' => '部门人员工资实发',
  189. 'd.管理人员工资' => '管理人员工资实发'
  190. ])
  191. ->where('a.Sys_ny', $month)
  192. ->group('a.Sys_ny, a.车间')
  193. ->select();
  194. if (empty($list)) {
  195. $this->success('未找到匹配数据', []);
  196. }
  197. $this->success('获取成功', $list);
  198. }
  199. /**
  200. * 月度人工数据下方工单详情
  201. * @return void
  202. * @throws \think\db\exception\DataNotFoundException
  203. * @throws \think\db\exception\ModelNotFoundException
  204. * @throws \think\exception\DbException
  205. */
  206. public function ArtificialDetailList()
  207. {
  208. if ($this->request->isGet() === false) {
  209. $this->error('请求错误');
  210. }
  211. $param = $this->request->param();
  212. if (empty($param)) {
  213. $this->error('参数错误');
  214. }
  215. $month = $param['month'];
  216. $sist = $param['sist'];
  217. $list = db('工单_质量考核汇总')
  218. ->alias('a')
  219. ->join('设备_基本资料 b', 'a.sczl_jtbh = b.设备编号')
  220. ->join('工单_印件资料 c', 'a.Gy0_gdbh = c.Yj_Gdbh and a.印件及工序 = c.yj_Yjno')
  221. ->join('工单_工艺资料 d', 'a.Gy0_gdbh = d.Gy0_gdbh and a.印件及工序 = d.Gy0_yjno and a.工序 = d.Gy0_gxh')
  222. ->field([
  223. 'a.sys_ny' => '年月',
  224. 'a.Gy0_gdbh' => '工单编号',
  225. 'a.印件及工序' => '印件号',
  226. 'a.工序' => '工序号',
  227. 'c.yj_yjmc' => '印件名称',
  228. 'd.Gy0_gxmc' => '工序名称',
  229. 'a.印件工序产量' => '班组车头产量',
  230. 'd.工价系数' => '工序难度系数',
  231. 'SUM(a.CjsJe)' => '计件工资',
  232. 'rtrim(b.使用部门)' => '车间名称',
  233. ])
  234. ->where('a.Sys_ny', $month)
  235. ->where('b.使用部门', $sist)
  236. ->group('a.Sys_ny, a.Gy0_gdbh,a.印件及工序,a.印件及工序')
  237. ->order('a.Gy0_gdbh')
  238. ->select();
  239. if (empty($list)) {
  240. $this->success('未找到数据');
  241. }else{
  242. $this->success('成功', $list);
  243. }
  244. }
  245. /**
  246. * 水电气直接费用右侧列表
  247. * @return void
  248. * @throws \think\db\exception\DataNotFoundException
  249. * @throws \think\db\exception\ModelNotFoundException
  250. * @throws \think\exception\DbException
  251. */
  252. public function shuidianqiList()
  253. {
  254. if ($this->request->isGet() === false) {
  255. $this->error('请求错误');
  256. }
  257. $param = $this->request->param();
  258. if (empty($param)) {
  259. $this->error('参数错误');
  260. }
  261. $month = $param['month'];
  262. $sist = $param['sist'];
  263. $list = db('成本_各月水电气')
  264. ->field('rtrim(部门名称) as 部门名称,rtrim(设备编号) as 设备编号,rtrim(科目名称) as 设备名称,rtrim(耗电量) as 耗电量,
  265. rtrim(单位电价) as 单位电价,rtrim(耗气量) as 耗气量,rtrim(单位气价) as 单位气价,rtrim(Sys_id) as 创建用户,Sys_rq as 创建时间,UniqID,耗电量*单位电价 as 直接费用合计')
  266. ->where('Sys_ny', $month)
  267. ->where('部门名称', $sist)
  268. ->where('费用类型', '直接')
  269. ->group('Sys_ny, Sys_rq, UniqID')
  270. ->select();
  271. if (empty($list)) {
  272. $this->success('未找到数据');
  273. }else{
  274. $this->success('成功', $list);
  275. }
  276. }
  277. /**
  278. * 水电气下方工单详情
  279. * @return void
  280. * @throws \think\db\exception\DataNotFoundException
  281. * @throws \think\db\exception\ModelNotFoundException
  282. * @throws \think\exception\DbException
  283. */
  284. public function shuidianqiDetailList()
  285. {
  286. if ($this->request->isGet() === false) {
  287. $this->error('请求错误');
  288. }
  289. $param = $this->request->param();
  290. if (empty($param)) {
  291. $this->error('参数错误');
  292. }
  293. $month = substr($param['month'], 0, 4) . '-' . substr($param['month'], 4, 2);
  294. $machine = $param['machine'];
  295. $list = db('设备_产量计酬')
  296. ->alias('a')
  297. ->join('工单_印件资料 b', 'a.sczl_gdbh = b.Yj_Gdbh and a.sczl_yjno = b.yj_Yjno')
  298. ->field('a.sczl_gdbh as 工单编号,b.yj_yjmc as 印件名称,a.sczl_yjno as 印件号,a.sczl_gxh as 工序号,
  299. sum(a.sczl_cl)*a.sczl_ls as 班组车头产量,sum(a.sczl_设备运行工时) as 占用机时')
  300. ->where('a.sczl_rq','like', '%'.$month.'%')
  301. ->where('a.sczl_jtbh', $machine)
  302. ->group('a.sczl_gdbh, a.sczl_yjno, a.sczl_gxh')
  303. ->select();
  304. if (empty($list)) {
  305. $this->success('未找到数据');
  306. }
  307. foreach ($list as $k => $v) {
  308. $list[$k]['计件产量'] = $v['班组车头产量'];
  309. $list[$k]['水电气分摊因子'] = $v['占用机时'];
  310. $list[$k]['年月'] = $param['month'];
  311. }
  312. $this->success('成功', $list);
  313. }
  314. /**
  315. * 水电气分摊费用
  316. * @return void
  317. * @throws \think\db\exception\DataNotFoundException
  318. * @throws \think\db\exception\ModelNotFoundException
  319. * @throws \think\exception\DbException
  320. */
  321. public function shuidianqifentanList()
  322. {
  323. if ($this->request->isGet() === false) {
  324. $this->error('请求错误');
  325. }
  326. $param = $this->request->param();
  327. if (empty($param)) {
  328. $this->error('参数错误');
  329. }
  330. $month = $param['month'];
  331. $list = db('成本_各月水电气')
  332. ->field('rtrim(部门名称) as 部门名称,rtrim(设备编号) as 设备编号,rtrim(科目名称) as 设备名称,rtrim(耗电量) as 耗电量,
  333. rtrim(单位电价) as 单位电价,rtrim(耗气量) as 耗气量,rtrim(单位气价) as 单位气价,rtrim(Sys_id) as 创建用户,Sys_rq as 创建时间,UniqID,耗电量*单位电价 as 直接费用合计')
  334. ->where('Sys_ny', $month)
  335. ->where('费用类型', '分摊')
  336. ->group('Sys_ny, Sys_rq, UniqID')
  337. ->select();
  338. if (empty($list)) {
  339. $this->success('未找到数据');
  340. }else{
  341. $this->success('成功', $list);
  342. }
  343. }
  344. /**
  345. * 各月工单人工明细
  346. * @return void
  347. * @throws \think\db\exception\BindParamException
  348. * @throws \think\db\exception\DataNotFoundException
  349. * @throws \think\db\exception\ModelNotFoundException
  350. * @throws \think\exception\DbException
  351. * @throws \think\exception\PDOException
  352. */
  353. public function ChromaticityAdd()
  354. {
  355. if ($this->request->isGet() === false) {
  356. $this->error('请求错误');
  357. }
  358. $param = $this->request->param();
  359. if (empty($param)) {
  360. $this->error('参数错误');
  361. }
  362. $list = db('绩效工资汇总')
  363. ->alias('a')
  364. ->join('工单_工艺资料 b','a.sczl_gdbh = b.Gy0_gdbh and a.sczl_yjno = b.Gy0_yjno and a.sczl_gxh = b.Gy0_gxh')
  365. ->join('设备_基本资料 c','a.sczl_jtbh = c.设备编号','LEFT')
  366. ->join('工单_印件资料 d','a.sczl_gdbh = d.Yj_Gdbh and a.sczl_yjno = d.yj_Yjno')
  367. ->field('a.sczl_gdbh as 工单编号,a.sczl_yjno as 印件号,a.sczl_gxh as 工序号,sum(a.班组车头产量) as 班组车头产量,b.Gy0_gxmc as 工序名称,
  368. a.sczl_ms as 墨色数,c.使用部门,b.印刷方式,b.版距,b.工价系数,a.sczl_jtbh,d.yj_yjmc as 印件名称,sum(a.车头产量占用机时) as 占用机时,a.sys_rq as 年月,
  369. a.工序难度系数,sum(a.班组换算产量) as 班组换算产量,a.千件工价')
  370. ->where('a.sys_ny', $param['month'])
  371. ->group('a.sczl_gdbh,a.sczl_yjno,a.sczl_gxh,a.sczl_jtbh')
  372. ->select();
  373. $data = [];
  374. foreach ($list as $k => $v) {
  375. if ($v['版距'] === '0.0'){
  376. $list[$k]['版距'] = 1000;
  377. }
  378. if ($v['墨色数'] === '0.00'){
  379. $list[$k]['墨色数'] = 1;
  380. }
  381. if (strpos($v['工序名称'],'切废')){
  382. $list[$k]['墨色数'] = 0.2;
  383. }
  384. $chanliang = $v['班组车头产量']*$v['工序难度系数'] + $v['班组换算产量'];
  385. $data[] = [
  386. '车间名称' => $v['使用部门'],
  387. 'sys_ny' => $param['month'],
  388. 'sczl_gdbh' => $v['工单编号'],
  389. '印件名称' => $v['印件名称'],
  390. 'sczl_yjno' => $v['印件号'],
  391. 'sczl_gxh' => $v['工序号'],
  392. '工序名称' => $v['工序名称'],
  393. 'sczl_jtbh' => $v['sczl_jtbh'],
  394. '卷张换算系数' => $list[$k]['版距']/1000,
  395. '占用机时' => $v['占用机时'],
  396. '班组车头产量' => $v['班组车头产量'],
  397. 'sczl_ms' => $list[$k]['墨色数'],
  398. '工序难度系数' => $v['工序难度系数'],
  399. '班组换算产量' => $v['班组换算产量'],
  400. '千件工价' => $v['千件工价'],
  401. '计件产量' => $chanliang,
  402. '水电分摊因子' => $v['占用机时'],
  403. '材料分摊因子' => $chanliang,
  404. '人工分摊因子' => ($chanliang/1000)*$v['千件工价'],
  405. 'Sys_id' => $param['sys_id'],
  406. 'Sys_rq' => date('Y-m-d H:i:s', time())
  407. ];
  408. }
  409. $sql = db('成本v23_月度成本明细')->fetchSql(true)->insertAll($data);
  410. $res = db()->query($sql);
  411. if ($res !== false) {
  412. $this->success('成功');
  413. }else{
  414. $this->error('失败');
  415. }
  416. }
  417. /**
  418. * 各月工单色度数
  419. * @return void
  420. * @throws \think\db\exception\BindParamException
  421. * @throws \think\db\exception\DataNotFoundException
  422. * @throws \think\db\exception\ModelNotFoundException
  423. * @throws \think\exception\DbException
  424. * @throws \think\exception\PDOException
  425. */
  426. public function ChromaticityDetailAdd()
  427. {
  428. if ($this->request->isGet() === false) {
  429. $this->error('请求错误');
  430. }
  431. $param = $this->request->param();
  432. if (empty($param)) {
  433. $this->error('参数错误');
  434. }
  435. $month = substr($param['month'], 0, 4) . '-' . substr($param['month'], 4, 2);
  436. $list = db('设备_产量计酬')
  437. ->alias('a')
  438. ->join('设备_基本资料 b','a.sczl_jtbh = b.设备编号')
  439. ->join('工单_工艺资料 c','a.sczl_gdbh = c.Gy0_gdbh and a.sczl_yjno = c.Gy0_yjno and a.sczl_gxh = c.Gy0_gxh')
  440. ->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.使用部门,
  441. sum(a.sczl_设备运行工时) as 通电工时,a.sczl_dedh,c.Gy0_gxmc')
  442. ->where('a.sczl_rq','like', $month.'%')
  443. ->group('a.sczl_gdbh,a.sczl_yjno,a.sczl_gxh,a.sczl_jtbh')
  444. ->select();
  445. if (empty($list)) {
  446. $this->error('没找到生产数据');
  447. }
  448. $data = [];
  449. foreach ($list as $k => $v) {
  450. if ($v['sczl_ms'] === '0.00'){
  451. $list[$k]['sczl_ms'] = 1;
  452. }
  453. if (strpos($v['Gy0_gxmc'],'切废') !== false){
  454. $list[$k]['sczl_ms'] = 0.2;
  455. }
  456. $data[] = [
  457. '年月' => $param['month'],
  458. 'sczl_gdbh' => $v['sczl_gdbh'],
  459. 'sczl_yjno' => $v['sczl_yjno'],
  460. 'sczl_gxh' => $v['sczl_gxh'],
  461. 'sczl_jtbh' => $v['sczl_jtbh'],
  462. 'sczl_gxmc' => $v['sczl_gxmc'],
  463. 'sczl_ms' => $v['sczl_ms'],
  464. 'sczl_dedh' => $v['sczl_dedh'],
  465. '通电时间' => $v['通电工时'],
  466. 'sczl_cl' => $v['产量'],
  467. '部门' => $v['使用部门'],
  468. 'Sys_ID' => $param['sys_id'],
  469. 'Sys_Rq' => date('Y-m-d H:i:s', time())
  470. ];
  471. }
  472. if (db('成本_各月色度数')->where('年月',$param['month'])->count() !== 0) {
  473. db('成本_各月色度数')->where('年月',$param['month'])->delete();
  474. }
  475. $sql = db('成本_各月色度数')->fetchSql(true)->insertAll($data);
  476. $res = db()->query($sql);
  477. if ($res !== false) {
  478. $this->success('成功');
  479. }else{
  480. $this->error('失败');
  481. }
  482. }
  483. /**
  484. * 各月车间色度数列表
  485. * @return void
  486. * @throws \think\db\exception\DataNotFoundException
  487. * @throws \think\db\exception\ModelNotFoundException
  488. * @throws \think\exception\DbException
  489. */
  490. public function ChromaticityDetailList()
  491. {
  492. if ($this->request->isGet() === false) {
  493. $this->error('请求错误');
  494. }
  495. $param = $this->request->param();
  496. if (empty($param)) {
  497. $this->error('参数错误');
  498. }
  499. // 执行统计查询
  500. $stats = db('成本_各月色度数')
  501. ->field([
  502. 'rtrim(部门) AS workshop',
  503. 'SUM(sczl_cl * IF(sczl_ms=0, 1, sczl_ms)) AS total'
  504. ])
  505. ->where('部门', '<>', '') // 过滤空车间数据
  506. ->where('sczl_cl', '>', 0) // 过滤无效产量
  507. ->where('年月', $param['month'])
  508. ->group('部门')
  509. ->select();
  510. // 构造中文返回结果
  511. $result = [];
  512. foreach ($stats as $item) {
  513. $result[] = [
  514. '年月' => $param['month'],
  515. '车间' => $item['workshop'],
  516. '色度数' => number_format($item['total'], 2)
  517. ];
  518. }
  519. $this->success('成功', $result);
  520. }
  521. /**
  522. * 车间色度数详情列表
  523. * @return void
  524. * @throws \think\db\exception\DataNotFoundException
  525. * @throws \think\db\exception\ModelNotFoundException
  526. * @throws \think\exception\DbException
  527. */
  528. public function MonochromaticDetailList()
  529. {
  530. if ($this->request->isGet() === false) {
  531. $this->error('请求错误');
  532. }
  533. $param = $this->request->param();
  534. if (empty($param)) {
  535. $this->error('参数错误');
  536. }
  537. $list = db('成本_各月色度数')
  538. ->where('年月', $param['month'])
  539. ->where('部门', $param['sist'])
  540. ->order('sczl_gdbh')
  541. ->select();
  542. $this->success('成功', $list);
  543. }
  544. /**
  545. * 车间成本核算汇总
  546. * @return void
  547. * @throws \think\db\exception\DataNotFoundException
  548. * @throws \think\db\exception\ModelNotFoundException
  549. * @throws \think\exception\DbException
  550. */
  551. public function SummaryCostAccountingList()
  552. {
  553. if ($this->request->isGet() === false) {
  554. $this->error('请求错误');
  555. }
  556. $param = $this->request->param();
  557. if (empty($param)) {
  558. $this->error('参数错误');
  559. }
  560. $list = db('成本v23_月度成本明细')
  561. ->where('车间名称', $param['sist'])
  562. ->where('sys_ny', $param['month'])
  563. ->order('sczl_gdbh')
  564. ->select();
  565. if (empty($list)) {
  566. $this->error('未找到数据');
  567. }else{
  568. $this->success('成功', $list);
  569. }
  570. }
  571. /**
  572. * 创建各月水电气分摊
  573. * @return void
  574. * @throws \think\db\exception\BindParamException
  575. * @throws \think\exception\PDOException
  576. */
  577. public function UtilitiesAdd()
  578. {
  579. if ($this->request->isPost() === false) {
  580. $this->error('请求错误');
  581. }
  582. $param = Request::instance()->post();
  583. if (empty($param)) {
  584. $this->error('参数错误');
  585. }
  586. $data = [];
  587. foreach ($param as $k => $v) {
  588. $data[] = [
  589. 'Sys_ny' => $v['sys_ny'],
  590. '部门名称' => $v['sist'],
  591. '费用类型' => '分摊',
  592. '科目名称' => $v['科目名称'],
  593. '耗电量' => $v['耗电量'],
  594. '单位电价' => $v['单位电价'],
  595. '耗气量' => $v['耗气量'],
  596. '单位气价' => $v['单位气价'],
  597. 'Sys_id' => $v['sys_id'],
  598. 'Sys_rq' => date('Y-m-d H:i:s', time())
  599. ];
  600. }
  601. $result = db('成本_各月水电气')->where('Sys_ny', $data[0]['Sys_ny'])->where('费用类型','分摊')->delete();
  602. $sql = db('成本_各月水电气')->fetchSql(true)->insertAll($data);
  603. $res = db()->query($sql);
  604. if ($res !== false) {
  605. $this->success('成功');
  606. }else{
  607. $this->error('失败');
  608. }
  609. }
  610. /**
  611. * 各月水电气分摊费用列表
  612. * @return void
  613. * @throws \think\db\exception\DataNotFoundException
  614. * @throws \think\db\exception\ModelNotFoundException
  615. * @throws \think\exception\DbException
  616. */
  617. public function UtilitiesList()
  618. {
  619. if($this->request->isGet() === false){
  620. $this->error('请求错误');
  621. }
  622. $param = $this->request->param();
  623. if (empty($param)) {
  624. $this->error('参数错误');
  625. }
  626. $list = db('成本_各月水电气')
  627. ->field('rtrim(部门名称) as 部门名称,rtrim(科目名称) as 科目名称,耗电量,单位电价,耗气量,单位气价')
  628. ->where('费用类型', '分摊')
  629. ->where('Sys_ny', $param['month'])
  630. ->group('部门名称,科目名称')
  631. ->select();
  632. if (empty($list)) {
  633. $list = db('成本_各月水电气')
  634. ->field('rtrim(部门名称) as 部门名称,rtrim(科目名称) as 科目名称')
  635. ->where('费用类型', '分摊')
  636. ->group('部门名称,科目名称')
  637. ->select();
  638. }
  639. foreach ($list as $k => $v) {
  640. $list[$k]['年月'] = $param['month'];
  641. }
  642. $this->success('成功', $list);
  643. }
  644. /**
  645. * 成本汇总左侧列表
  646. * @return void
  647. */
  648. public function getSummaryTab()
  649. {
  650. if ($this->request->isGet() === false) {
  651. $this->error('请求错误');
  652. }
  653. $months = db('成本v23_月度成本明细')
  654. ->field('sys_ny AS year_month')
  655. ->group('Sys_ny')
  656. ->order('Sys_ny DESC')
  657. ->column('Sys_ny');
  658. $sist = ['胶印车间','凹丝印车间','印后车间','检验车间'];
  659. $data = [];
  660. foreach ($months as $month) {
  661. $data[$month] = $sist;
  662. }
  663. $this->success('成功', $data);
  664. }
  665. //计算每个车间色度数
  666. private function CountSistChromaticity($month,$sist)
  667. {
  668. $data = db('成本v23_月度成本明细')
  669. ->where('sys_ny', $month)
  670. ->where('车间名称', $sist)
  671. ->group('车间名称')
  672. ->value('班组车头产量*sczl_ms as 色度数');
  673. return $data;
  674. }
  675. //计算每个机台色度数
  676. private function CountMachineChromatic($month,$sist)
  677. {
  678. $data = db('成本v23_月度成本明细')
  679. ->where('sys_ny', $month)
  680. ->where('车间名称', $sist)
  681. ->group('sczl_jtbh')
  682. ->value('班组车头产量*sczl_ms as 色度数');
  683. return $data;
  684. }
  685. //水电气分摊费用下方明细列表
  686. public function shuidianqiMachineDetailList()
  687. {
  688. if ($this->request->isGet() === false) {
  689. $this->error('请求错误');
  690. }
  691. $param = $this->request->param();
  692. if (empty($param)) {
  693. $this->error('参数错误');
  694. }
  695. $sist = ['胶印车间','凹丝印车间','印后车间','检验车间'];
  696. if (strpos($param['sist'],'车间') === false) {
  697. $number = db('成本_各月水电气')
  698. ->where('Sys_ny', $param['month'])
  699. ->where('部门名称', $param['sist'])
  700. ->where('费用类型', '分摊')
  701. ->value('');
  702. }else{
  703. $machineList = db('设备_基本资料')
  704. ->where('使用部门', $param['sist'])
  705. ->where('sys_sbID', '<>', '')
  706. ->order('设备编号')
  707. ->column('设备编号');
  708. }
  709. }
  710. /**
  711. * 其他待摊费用
  712. * @return void
  713. * @throws \think\db\exception\BindParamException
  714. * @throws \think\exception\PDOException
  715. */
  716. public function PrepaidExpensesListEdit()
  717. {
  718. if ($this->request->isPost() === false) {
  719. $this->error('请求错误');
  720. }
  721. $param = Request::instance()->post();
  722. if (empty($param)) {
  723. $this->error('参数错误');
  724. }
  725. $data = [
  726. 'sys_ny' => $param['month'],
  727. '部门人员工资' => $param['salary1'],
  728. '管理人员工资' => $param['salary2'],
  729. '场地租金' => $param['rental'],
  730. '待摊折旧' => $param['depreciation'],
  731. '工资成本占比' => $param['proportion'],
  732. '其他' => $param['rest'],
  733. '后勤人员工资' => $param['profit'],
  734. 'sys_id' => $param['sys_id'],
  735. ];
  736. $result = db('成本_各月其他费用')->where('sys_ny', $param['month'])->count();
  737. if ($result > 0) {
  738. $data['mod_rq'] = date('Y-m-d H:i:s', time());
  739. $sql = db('成本_各月其他费用')->where('sys_ny', $param['month'])->fetchSql(true)->update($data);
  740. }else{
  741. $data['sys_rq'] = date('Y-m-d H:i:s', time());
  742. $sql = db('成本_各月其他费用')
  743. ->fetchSql(true)
  744. ->insert($data);
  745. }
  746. $res = db()->query($sql);
  747. if ($res !== false) {
  748. $this->success('成功');
  749. }else{
  750. $this->error('失败');
  751. }
  752. }
  753. /**
  754. * 其他待摊费用列表
  755. * @return void
  756. * @throws \think\db\exception\DataNotFoundException
  757. * @throws \think\db\exception\ModelNotFoundException
  758. * @throws \think\exception\DbException
  759. */
  760. public function PrepaidExpensesList()
  761. {
  762. if ($this->request->isGet() === false) {
  763. $this->error('请求错误');
  764. }
  765. $param = $this->request->param();
  766. if (empty($param)) {
  767. $this->error('参数错误');
  768. }
  769. $list = db('成本_各月其他费用')
  770. ->where('sys_ny', $param['month'])
  771. ->field('sys_ny as 年月,部门人员工资,管理人员工资,场地租金,待摊折旧,工资成本占比,其他,后勤人员工资,sys_id as 创建用户,sys_rq as 创建时间,mod_rq as 修改时间,UniqID')
  772. ->find();
  773. if (empty($list)) {
  774. $this->error('未找到数据');
  775. }else{
  776. $this->success('成功', $list);
  777. }
  778. }
  779. /**
  780. * 参考其他费用参考月份
  781. * @return void
  782. * @throws \think\db\exception\BindParamException
  783. * @throws \think\db\exception\DataNotFoundException
  784. * @throws \think\db\exception\ModelNotFoundException
  785. * @throws \think\exception\DbException
  786. * @throws \think\exception\PDOException
  787. */
  788. public function PrepaidExpensesDetailCopy()
  789. {
  790. if ($this->request->isGet() === false) {
  791. $this->error('请求错误');
  792. }
  793. $param = $this->request->param();
  794. if (empty($param)) {
  795. $this->error('参数错误');
  796. }
  797. $formMonth = $param['formMonth'];
  798. $toMonth = $param['toMonth'];
  799. $list = db('成本_各月其他费用')
  800. ->where('sys_ny', $formMonth)
  801. ->field('管理人员工资,场地租金,待摊折旧,工资成本占比,后勤人员工资')
  802. ->find();
  803. $list['sys_ny'] = $toMonth;
  804. $list['sys_id'] = $param['sys_id'];
  805. $list['sys_rq'] = date('Y-m-d H:i:s', time());
  806. $sql = db('成本_各月其他费用')
  807. ->fetchSql(true)
  808. ->insert($list);
  809. $res = db()->query($sql);
  810. if ($res !== false) {
  811. $this->success('成功');
  812. }else{
  813. $this->error('失败');
  814. }
  815. }
  816. /**
  817. * 各月水电气直接费用创建
  818. * @return void
  819. * @throws \think\db\exception\BindParamException
  820. * @throws \think\db\exception\DataNotFoundException
  821. * @throws \think\db\exception\ModelNotFoundException
  822. * @throws \think\exception\DbException
  823. * @throws \think\exception\PDOException
  824. */
  825. public function shuidianqiDetailAdd()
  826. {
  827. if ($this->request->isGet() === false) {
  828. $this->error('请求错误');
  829. }
  830. $param = $this->request->param();
  831. if (empty($param)) {
  832. $this->error('参数错误');
  833. }
  834. $month = substr($param['month'], 0, 4) . '-' . substr($param['month'], 4, 2);
  835. $sist = ['胶印车间','凹丝印车间','印后车间'];
  836. $list = db('设备_产量计酬')
  837. ->alias('a')
  838. ->join('设备_基本资料 b', 'a.sczl_jtbh = b.设备编号')
  839. ->where('a.sczl_rq', 'like', $month . '%')
  840. ->where('b.sys_sbID','<>','')
  841. ->where('b.使用部门','in',$sist)
  842. ->field('a.sczl_jtbh,sum(a.sczl_设备运行工时) as 通电工时,b.使用部门,rtrim(b.设备名称) as 设备名称')
  843. ->order('b.使用部门,a.sczl_jtbh')
  844. ->group('a.sczl_jtbh')
  845. ->select();
  846. $data = [];
  847. foreach ($list as $k => $v) {
  848. $data[] = [
  849. 'Sys_ny' => $param['month'],
  850. '部门名称' => $v['使用部门'],
  851. '费用类型' => '直接',
  852. '设备编号' => $v['sczl_jtbh'],
  853. '科目名称' => $v['设备名称'],
  854. '耗电量' => $v['通电工时'],
  855. '单位电价' => 0.69,
  856. 'Sys_id' => $param['sys_id'],
  857. 'Sys_rq' => date('Y-m-d H:i:s', time()),
  858. ];
  859. }
  860. $sql = db('成本_各月水电气')->fetchSql(true)->insertAll($data);
  861. $res = db()->query($sql);
  862. if ($res !== false) {
  863. $this->success('成功');
  864. }else{
  865. $this->error('失败');
  866. }
  867. }
  868. //计算成本
  869. public function CostCalculation()
  870. {
  871. if ($this->request->isGet() === false) {
  872. $this->error('请求错误');
  873. }
  874. $param = $this->request->param();
  875. if (empty($param)) {
  876. $this->error('参数错误');
  877. }
  878. //查询工单数据
  879. $list = db('成本v23_月度成本明细')
  880. ->field('车间名称,sys_ny as 年月,sczl_gdbh as 工单编号,sczl_yjno as 印件号,sczl_gxh as 工序号,工序名称,sczl_jtbh as jtbh,
  881. 占用机时,计件产量,sczl_ms as 墨色数,Uniqid,计件产量*sczl_ms as 色度数')
  882. ->where('sys_ny', $param['month'])
  883. ->whereNotNull('车间名称')
  884. ->select();
  885. //查询整月全车间色度数之和
  886. $ChromaticityCount = db('成本v23_月度成本明细')
  887. ->where('sys_ny', $param['month'])
  888. ->whereNotNull('车间名称')
  889. ->column('sum(计件产量*sczl_ms)');
  890. //查询整月各车间色度数
  891. $MachineChromaticityCount = db('成本v23_月度成本明细')
  892. ->where('sys_ny', $param['month'])
  893. ->whereNotNull('车间名称')
  894. ->group('车间名称')
  895. ->column('sum(计件产量*sczl_ms)');
  896. //计算车间水电气
  897. $res = $this->ApportionmentOne($param['month']);
  898. halt($res);
  899. }
  900. //计算水电气分摊费用
  901. protected function ApportionmentOne($month)
  902. {
  903. $list = db('成本_各月水电气')
  904. ->where('Sys_ny', $month)
  905. ->where('费用类型','like','%分摊%')
  906. ->select();
  907. foreach ($list as $k => $v) {
  908. if ($v['科目名称'] == '待分摊总额') {
  909. $money = $v['耗电量'] * $v['单位电价'];
  910. $data = $this->MachineTime($v['部门名称'],$month);
  911. foreach ($data['machine'] as $k1 => $v1) {
  912. $data['machine'][$k1]['分摊水电'] = round($money*($v1['占用机时']/$data['sist']),2) ;
  913. }
  914. }elseif (strpos($v['科目名称'],'废气处理') !== false) {
  915. $electricityMoney = $v['耗电量'] * $v['单位电价'];
  916. $gasMoney = $v['耗气量'] * $v['单位气价'];
  917. $data = $this->MachineTime('03、卷凹机组',$month);
  918. foreach ($data['machine'] as $k1 => $v1) {
  919. $data['machine'][$k1]['分摊水电'] = round($electricityMoney*($v1['占用机时']/$data['sist']),2) ;
  920. $data['machine'][$k1]['废气处理'] = round($gasMoney*($v1['占用机时']/$data['sist']),2) ;
  921. }
  922. }elseif (strpos($v['科目名称'],'锅炉') !== false && strpos($v['科目名称'],'热水锅炉') === false) {
  923. $electricityMoney = $v['耗电量'] * $v['单位电价'];
  924. $gasMoney = $v['耗气量'] * $v['单位气价'];
  925. $data = $this->MachineTime('03、卷凹机组',$month);
  926. foreach ($data['machine'] as $k1 => $v1) {
  927. $data['machine'][$k1]['分摊水电'] = round($electricityMoney*($v1['占用机时']/$data['sist']),2) ;
  928. $data['machine'][$k1]['锅炉'] = round($gasMoney*($v1['占用机时']/$data['sist']),2) ;
  929. }
  930. }elseif (strpos($v['科目名称'],'空压机A') !== false) {
  931. $money = $v['耗电量'] * $v['单位电价'];
  932. $sistList = ['凹丝印车间','胶印车间','印后车间','检验车间'];
  933. $data = $this->MachineTime($sistList,$month);
  934. foreach ($data['machine'] as $k1 => $v1) {
  935. $data['machine'][$k1]['空压机A'] = round($money*($v1['占用机时']/$data['sist']),2) ;
  936. }
  937. }elseif (strpos($v['科目名称'],'空压机B') !== false) {
  938. $money = $v['耗电量'] * $v['单位电价'];
  939. $sistList = ['凹丝印车间','胶印车间','印后车间','检验车间'];
  940. $data = $this->MachineTime($sistList,$month);
  941. foreach ($data['machine'] as $k1 => $v1) {
  942. $data['machine'][$k1]['空压机B'] = round($money*($v1['占用机时']/$data['sist']),2) ;
  943. }
  944. }elseif (strpos($v['科目名称'],'热水锅炉') !== false){
  945. $money = $v['耗电量'] * $v['单位电价'];
  946. $sistList = ['凹丝印车间','胶印车间','印后车间','检验车间'];
  947. $data = $this->MachineTime($sistList,$month);
  948. foreach ($data['machine'] as $k1 => $v1) {
  949. $data['machine'][$k1]['热水锅炉'] = round($money*($v1['占用机时']/$data['sist']),2) ;
  950. }
  951. }
  952. }
  953. }
  954. //查询车间全部机台通电机时数据
  955. protected function MachineTime($sist,$month)
  956. {
  957. $where['a.sys_ny'] = $month;
  958. $where['b.sys_sbID'] = ['<>',''];
  959. if (is_array($sist)) {
  960. $where['a.车间名称'] = ['in',$sist];
  961. }else{
  962. if (strpos($sist,'机组') !== false) {
  963. $where['b.设备编组'] = $sist;
  964. }elseif (strpos($sist,'车间') !== false) {
  965. $where['a.车间名称'] = $sist;
  966. }
  967. }
  968. //查询各个工单工艺通电时间
  969. $machine = db('成本v23_月度成本明细')
  970. ->alias('a')
  971. ->join('设备_基本资料 b', 'a.sczl_jtbh = b.设备编号','left')
  972. ->field('a.sczl_gdbh as 工单编号,a.sczl_yjno as 印件号,a.sczl_gxh as 工序号,a.sczl_jtbh as 机台编号,a.占用机时,a.Uniqid')
  973. ->where($where)
  974. ->select();
  975. //查询各个车间通电总时长
  976. $sist = db('成本v23_月度成本明细')
  977. ->alias('a')
  978. ->join('设备_基本资料 b', 'a.sczl_jtbh = b.设备编号','left')
  979. ->where($where)
  980. ->value('sum(a.占用机时) as 占用机时');
  981. $data = [
  982. 'machine' => $machine,
  983. 'sist' => $sist
  984. ];
  985. return $data;
  986. }
  987. }