CostAccounting.php 38 KB

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