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