CostAccounting.php 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  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. foreach ($param as $k => $v) {
  568. $data[] = [
  569. 'Sys_ny' => $v['sys_ny'],
  570. '部门名称' => $v['sist'],
  571. '费用类型' => '分摊',
  572. '科目名称' => $v['科目名称'],
  573. '耗电量' => $v['耗电量']??0,
  574. '单位电价' => $v['单位电价'],
  575. '耗气量' => $v['耗气量']??0,
  576. '单位气价' => $v['单位气价'],
  577. 'Sys_id' => $v['sys_id'],
  578. 'Sys_rq' => date('Y-m-d H:i:s', time())
  579. ];
  580. }
  581. $result = db('成本_各月水电气')->where('Sys_ny', $data[0]['Sys_ny'])->where('费用类型','分摊')->delete();
  582. $sql = db('成本_各月水电气')->fetchSql(true)->insertAll($data);
  583. $res = db()->query($sql);
  584. if ($res !== false) {
  585. $this->success('成功');
  586. }else{
  587. $this->error('失败');
  588. }
  589. }
  590. /**
  591. * 各月水电气分摊费用列表
  592. * @return void
  593. * @throws \think\db\exception\DataNotFoundException
  594. * @throws \think\db\exception\ModelNotFoundException
  595. * @throws \think\exception\DbException
  596. */
  597. public function UtilitiesList()
  598. {
  599. if($this->request->isGet() === false){
  600. $this->error('请求错误');
  601. }
  602. $param = $this->request->param();
  603. if (empty($param)) {
  604. $this->error('参数错误');
  605. }
  606. $list = db('成本_各月水电气')
  607. ->field('rtrim(部门名称) as 部门名称,rtrim(科目名称) as 科目名称,耗电量,单位电价,耗气量,单位气价')
  608. ->where('费用类型', '分摊')
  609. ->where('Sys_ny', $param['month'])
  610. ->group('部门名称,科目名称')
  611. ->select();
  612. if (empty($list)) {
  613. $list = db('成本_各月水电气')
  614. ->field('rtrim(部门名称) as 部门名称,rtrim(科目名称) as 科目名称')
  615. ->where('费用类型', '分摊')
  616. ->group('部门名称,科目名称')
  617. ->select();
  618. }
  619. foreach ($list as $k => $v) {
  620. $list[$k]['年月'] = $param['month'];
  621. }
  622. $this->success('成功', $list);
  623. }
  624. /**
  625. * 成本汇总左侧列表
  626. * @return void
  627. */
  628. public function getSummaryTab()
  629. {
  630. if ($this->request->isGet() === false) {
  631. $this->error('请求错误');
  632. }
  633. $months = db('成本v23_月度成本明细')
  634. ->field('sys_ny AS year_month')
  635. ->group('Sys_ny')
  636. ->order('Sys_ny DESC')
  637. ->column('Sys_ny');
  638. $sist = ['胶印车间','凹丝印车间','印后车间','检验车间'];
  639. $data = [];
  640. foreach ($months as $month) {
  641. $data[$month] = $sist;
  642. }
  643. $this->success('成功', $data);
  644. }
  645. //计算每个车间色度数
  646. private function CountSistChromaticity($month,$sist)
  647. {
  648. $data = db('成本v23_月度成本明细')
  649. ->where('sys_ny', $month)
  650. ->where('车间名称', $sist)
  651. ->group('车间名称')
  652. ->value('班组车头产量*sczl_ms as 色度数');
  653. return $data;
  654. }
  655. //计算每个机台色度数
  656. private function CountMachineChromatic($month,$sist)
  657. {
  658. $data = db('成本v23_月度成本明细')
  659. ->where('sys_ny', $month)
  660. ->where('车间名称', $sist)
  661. ->group('sczl_jtbh')
  662. ->value('班组车头产量*sczl_ms as 色度数');
  663. return $data;
  664. }
  665. //水电气分摊费用下方明细列表
  666. public function shuidianqiMachineDetailList()
  667. {
  668. if ($this->request->isGet() === false) {
  669. $this->error('请求错误');
  670. }
  671. $param = $this->request->param();
  672. if (empty($param)) {
  673. $this->error('参数错误');
  674. }
  675. $sist = ['胶印车间','凹丝印车间','印后车间','检验车间'];
  676. if (strpos($param['sist'],'车间') === false) {
  677. $number = db('成本_各月水电气')
  678. ->where('Sys_ny', $param['month'])
  679. ->where('部门名称', $param['sist'])
  680. ->where('费用类型', '分摊')
  681. ->value('');
  682. }else{
  683. $machineList = db('设备_基本资料')
  684. ->where('使用部门', $param['sist'])
  685. ->where('sys_sbID', '<>', '')
  686. ->order('设备编号')
  687. ->column('设备编号');
  688. }
  689. }
  690. /**
  691. * 其他待摊费用
  692. * @return void
  693. * @throws \think\db\exception\BindParamException
  694. * @throws \think\exception\PDOException
  695. */
  696. public function PrepaidExpensesListEdit()
  697. {
  698. if ($this->request->isPost() === false) {
  699. $this->error('请求错误');
  700. }
  701. $param = Request::instance()->post();
  702. if (empty($param)) {
  703. $this->error('参数错误');
  704. }
  705. $data = [
  706. 'sys_ny' => $param['month'],
  707. '部门人员工资' => $param['salary1'],
  708. '管理人员工资' => $param['salary2'],
  709. '场地租金' => $param['rental'],
  710. '待摊折旧' => $param['depreciation'],
  711. '工资成本占比' => $param['proportion'],
  712. '其他' => $param['rest'],
  713. '后勤人员工资' => $param['profit'],
  714. 'sys_id' => $param['sys_id'],
  715. ];
  716. $result = db('成本_各月其他费用')->where('sys_ny', $param['month'])->count();
  717. if ($result > 0) {
  718. $data['mod_rq'] = date('Y-m-d H:i:s', time());
  719. $sql = db('成本_各月其他费用')->where('sys_ny', $param['month'])->fetchSql(true)->update($data);
  720. }else{
  721. $data['sys_rq'] = date('Y-m-d H:i:s', time());
  722. $sql = db('成本_各月其他费用')
  723. ->fetchSql(true)
  724. ->insert($data);
  725. }
  726. $res = db()->query($sql);
  727. if ($res !== false) {
  728. $this->success('成功');
  729. }else{
  730. $this->error('失败');
  731. }
  732. }
  733. /**
  734. * 其他待摊费用列表
  735. * @return void
  736. * @throws \think\db\exception\DataNotFoundException
  737. * @throws \think\db\exception\ModelNotFoundException
  738. * @throws \think\exception\DbException
  739. */
  740. public function PrepaidExpensesList()
  741. {
  742. if ($this->request->isGet() === false) {
  743. $this->error('请求错误');
  744. }
  745. $param = $this->request->param();
  746. if (empty($param)) {
  747. $this->error('参数错误');
  748. }
  749. $list = db('成本_各月其他费用')
  750. ->where('sys_ny', $param['month'])
  751. ->field('sys_ny as 年月,部门人员工资,管理人员工资,场地租金,待摊折旧,工资成本占比,其他,后勤人员工资,sys_id as 创建用户,sys_rq as 创建时间,mod_rq as 修改时间,UniqID')
  752. ->find();
  753. if (empty($list)) {
  754. $this->error('未找到数据');
  755. }else{
  756. $this->success('成功', $list);
  757. }
  758. }
  759. /**
  760. * 参考其他费用参考月份
  761. * @return void
  762. * @throws \think\db\exception\BindParamException
  763. * @throws \think\db\exception\DataNotFoundException
  764. * @throws \think\db\exception\ModelNotFoundException
  765. * @throws \think\exception\DbException
  766. * @throws \think\exception\PDOException
  767. */
  768. public function PrepaidExpensesDetailCopy()
  769. {
  770. if ($this->request->isGet() === false) {
  771. $this->error('请求错误');
  772. }
  773. $param = $this->request->param();
  774. if (empty($param)) {
  775. $this->error('参数错误');
  776. }
  777. $formMonth = $param['formMonth'];
  778. $toMonth = $param['toMonth'];
  779. $list = db('成本_各月其他费用')
  780. ->where('sys_ny', $formMonth)
  781. ->field('管理人员工资,场地租金,待摊折旧,工资成本占比,后勤人员工资')
  782. ->find();
  783. $list['sys_ny'] = $toMonth;
  784. $list['sys_id'] = $param['sys_id'];
  785. $list['sys_rq'] = date('Y-m-d H:i:s', time());
  786. $sql = db('成本_各月其他费用')
  787. ->fetchSql(true)
  788. ->insert($list);
  789. $res = db()->query($sql);
  790. if ($res !== false) {
  791. $this->success('成功');
  792. }else{
  793. $this->error('失败');
  794. }
  795. }
  796. /**
  797. * 各月水电气直接费用创建
  798. * @return void
  799. * @throws \think\db\exception\BindParamException
  800. * @throws \think\db\exception\DataNotFoundException
  801. * @throws \think\db\exception\ModelNotFoundException
  802. * @throws \think\exception\DbException
  803. * @throws \think\exception\PDOException
  804. */
  805. public function shuidianqiDetailAdd()
  806. {
  807. if ($this->request->isGet() === false) {
  808. $this->error('请求错误');
  809. }
  810. $param = $this->request->param();
  811. if (empty($param)) {
  812. $this->error('参数错误');
  813. }
  814. $month = substr($param['month'], 0, 4) . '-' . substr($param['month'], 4, 2);
  815. $sist = ['胶印车间','凹丝印车间','印后车间'];
  816. $list = db('设备_产量计酬')
  817. ->alias('a')
  818. ->join('设备_基本资料 b', 'a.sczl_jtbh = b.设备编号')
  819. ->where('a.sczl_rq', 'like', $month . '%')
  820. ->where('b.sys_sbID','<>','')
  821. ->where('b.使用部门','in',$sist)
  822. ->field('a.sczl_jtbh,sum(a.sczl_设备运行工时) as 通电工时,b.使用部门,rtrim(b.设备名称) as 设备名称')
  823. ->order('b.使用部门,a.sczl_jtbh')
  824. ->group('a.sczl_jtbh')
  825. ->select();
  826. $data = [];
  827. foreach ($list as $k => $v) {
  828. $data[] = [
  829. 'Sys_ny' => $param['month'],
  830. '部门名称' => $v['使用部门'],
  831. '费用类型' => '直接',
  832. '设备编号' => $v['sczl_jtbh'],
  833. '科目名称' => $v['设备名称'],
  834. '耗电量' => $v['通电工时'],
  835. '单位电价' => 0.69,
  836. 'Sys_id' => $param['sys_id'],
  837. 'Sys_rq' => date('Y-m-d H:i:s', time()),
  838. ];
  839. }
  840. $sql = db('成本_各月水电气')->fetchSql(true)->insertAll($data);
  841. $res = db()->query($sql);
  842. if ($res !== false) {
  843. $this->success('成功');
  844. }else{
  845. $this->error('失败');
  846. }
  847. }
  848. //计算成本
  849. // public function CostCalculation()
  850. // {
  851. // if ($this->request->isGet() === false) {
  852. // $this->error('请求错误');
  853. // }
  854. // $param = $this->request->param();
  855. // if (empty($param)) {
  856. // $this->error('参数错误');
  857. // }
  858. // //查询工单数据
  859. // $list = db('成本v23_月度成本明细')
  860. // ->field('车间名称,sys_ny as 年月,sczl_gdbh as 工单编号,sczl_yjno as 印件号,sczl_gxh as 工序号,工序名称,sczl_jtbh as jtbh,
  861. // 占用机时,计件产量,sczl_ms as 墨色数,Uniqid,计件产量*sczl_ms as 色度数')
  862. // ->where('sys_ny', $param['month'])
  863. // ->whereNotNull('车间名称')
  864. // ->select();
  865. // //查询整月全车间色度数之和
  866. // $ChromaticityCount = db('成本v23_月度成本明细')
  867. // ->where('sys_ny', $param['month'])
  868. // ->whereNotNull('车间名称')
  869. // ->column('sum(计件产量*sczl_ms)');
  870. // //查询整月各车间色度数
  871. // $MachineChromaticityCount = db('成本v23_月度成本明细')
  872. // ->where('sys_ny', $param['month'])
  873. // ->whereNotNull('车间名称')
  874. // ->group('车间名称')
  875. // ->column('sum(计件产量*sczl_ms)');
  876. // //计算车间水电气
  877. // $res = $this->ApportionmentOne($param['month']);
  878. // halt($res);
  879. //
  880. //
  881. //
  882. // }
  883. // //计算水电气分摊费用
  884. // protected function ApportionmentOne($month)
  885. // {
  886. // $list = db('成本_各月水电气')
  887. // ->where('Sys_ny', $month)
  888. // ->where('费用类型','like','%分摊%')
  889. // ->select();
  890. // foreach ($list as $k => $v) {
  891. // if ($v['科目名称'] == '待分摊总额') {
  892. // $money = $v['耗电量'] * $v['单位电价'];
  893. // $data = $this->MachineTime($v['部门名称'],$month);
  894. // foreach ($data['machine'] as $k1 => $v1) {
  895. // $data['machine'][$k1]['分摊水电'] = round($money*($v1['占用机时']/$data['sist']),2) ;
  896. // }
  897. // }elseif (strpos($v['科目名称'],'废气处理') !== false) {
  898. // $electricityMoney = $v['耗电量'] * $v['单位电价'];
  899. // $gasMoney = $v['耗气量'] * $v['单位气价'];
  900. // $data = $this->MachineTime('03、卷凹机组',$month);
  901. // foreach ($data['machine'] as $k1 => $v1) {
  902. // $data['machine'][$k1]['分摊水电'] = round($electricityMoney*($v1['占用机时']/$data['sist']),2) ;
  903. // $data['machine'][$k1]['废气处理'] = round($gasMoney*($v1['占用机时']/$data['sist']),2) ;
  904. // }
  905. // }elseif (strpos($v['科目名称'],'锅炉') !== false && strpos($v['科目名称'],'热水锅炉') === false) {
  906. // $electricityMoney = $v['耗电量'] * $v['单位电价'];
  907. // $gasMoney = $v['耗气量'] * $v['单位气价'];
  908. // $data = $this->MachineTime('03、卷凹机组',$month);
  909. // foreach ($data['machine'] as $k1 => $v1) {
  910. // $data['machine'][$k1]['分摊水电'] = round($electricityMoney*($v1['占用机时']/$data['sist']),2) ;
  911. // $data['machine'][$k1]['锅炉'] = round($gasMoney*($v1['占用机时']/$data['sist']),2) ;
  912. // }
  913. // }elseif (strpos($v['科目名称'],'空压机A') !== false) {
  914. // $money = $v['耗电量'] * $v['单位电价'];
  915. // $sistList = ['凹丝印车间','胶印车间','印后车间','检验车间'];
  916. // $data = $this->MachineTime($sistList,$month);
  917. // foreach ($data['machine'] as $k1 => $v1) {
  918. // $data['machine'][$k1]['空压机A'] = round($money*($v1['占用机时']/$data['sist']),2) ;
  919. // }
  920. // }elseif (strpos($v['科目名称'],'空压机B') !== false) {
  921. // $money = $v['耗电量'] * $v['单位电价'];
  922. // $sistList = ['凹丝印车间','胶印车间','印后车间','检验车间'];
  923. // $data = $this->MachineTime($sistList,$month);
  924. // foreach ($data['machine'] as $k1 => $v1) {
  925. // $data['machine'][$k1]['空压机B'] = round($money*($v1['占用机时']/$data['sist']),2) ;
  926. // }
  927. // }elseif (strpos($v['科目名称'],'热水锅炉') !== false){
  928. // $money = $v['耗电量'] * $v['单位电价'];
  929. // $sistList = ['凹丝印车间','胶印车间','印后车间','检验车间'];
  930. // $data = $this->MachineTime($sistList,$month);
  931. // foreach ($data['machine'] as $k1 => $v1) {
  932. // $data['machine'][$k1]['热水锅炉'] = round($money*($v1['占用机时']/$data['sist']),2) ;
  933. // }
  934. // }
  935. // }
  936. // }
  937. //
  938. // //查询车间全部机台通电机时数据
  939. // protected function MachineTime($sist,$month)
  940. // {
  941. // $where['a.sys_ny'] = $month;
  942. // $where['b.sys_sbID'] = ['<>',''];
  943. // if (is_array($sist)) {
  944. // $where['a.车间名称'] = ['in',$sist];
  945. // }else{
  946. // if (strpos($sist,'机组') !== false) {
  947. // $where['b.设备编组'] = $sist;
  948. // }elseif (strpos($sist,'车间') !== false) {
  949. // $where['a.车间名称'] = $sist;
  950. // }
  951. // }
  952. // //查询各个工单工艺通电时间
  953. // $machine = db('成本v23_月度成本明细')
  954. // ->alias('a')
  955. // ->join('设备_基本资料 b', 'a.sczl_jtbh = b.设备编号','left')
  956. // ->field('a.sczl_gdbh as 工单编号,a.sczl_yjno as 印件号,a.sczl_gxh as 工序号,a.sczl_jtbh as 机台编号,a.占用机时,a.Uniqid')
  957. // ->where($where)
  958. // ->select();
  959. // //查询各个车间通电总时长
  960. // $sist = db('成本v23_月度成本明细')
  961. // ->alias('a')
  962. // ->join('设备_基本资料 b', 'a.sczl_jtbh = b.设备编号','left')
  963. // ->where($where)
  964. // ->value('sum(a.占用机时) as 占用机时');
  965. // $data = [
  966. // 'machine' => $machine,
  967. // 'sist' => $sist
  968. // ];
  969. // return $data;
  970. // }
  971. }