Invoice.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------------------------------
  4. * GouGuOPEN [ 左手研发,右手开源,未来可期!]
  5. +-----------------------------------------------------------------------------------------------
  6. * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
  7. +-----------------------------------------------------------------------------------------------
  8. * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
  9. +-----------------------------------------------------------------------------------------------
  10. * @Author 勾股工作室 <hdm58@qq.com>
  11. +-----------------------------------------------------------------------------------------------
  12. */
  13. declare (strict_types = 1);
  14. namespace app\finance\controller;
  15. use app\base\BaseController;
  16. use app\finance\model\Invoice as InvoiceModel;
  17. use app\finance\validate\InvoiceValidate;
  18. use think\exception\ValidateException;
  19. use think\facade\Db;
  20. use think\facade\View;
  21. class Invoice extends BaseController
  22. {
  23. /**
  24. * 构造函数
  25. */
  26. protected $model;
  27. public function __construct()
  28. {
  29. parent::__construct(); // 调用父类构造函数
  30. $this->model = new InvoiceModel();
  31. }
  32. /**
  33. * 数据列表
  34. */
  35. public function datalist()
  36. {
  37. $param = get_params();
  38. if (request()->isAjax()) {
  39. $tab = isset($param['tab']) ? $param['tab'] : 0;
  40. $uid=$this->uid;
  41. $where = array();
  42. $whereOr = array();
  43. $where[]=['delete_time','=',0];
  44. $where[]=['invoice_type','>',0];
  45. if($tab == 0){
  46. $auth = isAuthInvoice($uid);
  47. if($auth == 0){
  48. $whereOr[] = ['admin_id', '=', $this->uid];
  49. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
  50. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
  51. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
  52. $dids_a = get_leader_departments($uid);
  53. $dids_b = get_role_departments($uid);
  54. $dids = array_merge($dids_a, $dids_b);
  55. if(!empty($dids)){
  56. $whereOr[] = ['did','in',$dids];
  57. }
  58. }
  59. }
  60. if($tab == 1){
  61. //我创建的
  62. $where[] = ['admin_id', '=', $this->uid];
  63. }
  64. if($tab == 2){
  65. //待我审核的
  66. $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
  67. }
  68. if($tab == 3){
  69. //我已审核的
  70. $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
  71. }
  72. if($tab == 4){
  73. //抄送给我的
  74. $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
  75. }
  76. if($tab == 5){
  77. //已开具的
  78. $where[] = ['open_status', '=', 1];
  79. }
  80. if($tab == 6){
  81. //已作废的
  82. $where[] = ['open_status', '=', 2];
  83. }
  84. //按时间检索
  85. if (!empty($param['diff_time'])) {
  86. $diff_time =explode('~', $param['diff_time']);
  87. $where[] = ['open_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1].' 23:59:59'))]];
  88. }
  89. if (isset($param['open_status']) && $param['open_status'] != "") {
  90. $where[] = ['open_status', '=', $param['open_status']];
  91. }
  92. if (isset($param['enter_status']) && $param['enter_status'] != "") {
  93. $where[] = ['enter_status', '=', $param['enter_status']];
  94. }
  95. if (isset($param['check_status']) && $param['check_status'] != "") {
  96. $where[] = ['check_status', '=', $param['check_status']];
  97. }
  98. $list = $this->model->datalist($param,$where,$whereOr);
  99. return table_assign(0, '', $list);
  100. }
  101. else{
  102. return view();
  103. }
  104. }
  105. /**
  106. * 添加/编辑
  107. */
  108. public function add()
  109. {
  110. $param = get_params();
  111. if (request()->isAjax()) {
  112. if ($param['types'] == 1) {
  113. if (!$param['invoice_bank']) {
  114. return to_assign(1, '开户银行不能为空');
  115. }
  116. if (!$param['invoice_account']) {
  117. return to_assign(1, '银行账号不能为空');
  118. }
  119. }
  120. $param['admin_id'] = $this->uid;
  121. $param['did'] = $this->did;
  122. if (!empty($param['id']) && $param['id'] > 0) {
  123. try {
  124. validate(InvoiceValidate::class)->scene('edit')->check($param);
  125. } catch (ValidateException $e) {
  126. // 验证失败 输出错误信息
  127. return to_assign(1, $e->getError());
  128. }
  129. $this->model->edit($param);
  130. } else {
  131. try {
  132. validate(InvoiceValidate::class)->scene('add')->check($param);
  133. } catch (ValidateException $e) {
  134. // 验证失败 输出错误信息
  135. return to_assign(1, $e->getError());
  136. }
  137. $this->model->add($param);
  138. }
  139. }else{
  140. $id = isset($param['id']) ? $param['id'] : 0;
  141. if ($id>0) {
  142. $detail = $this->model->getById($id);
  143. View::assign('detail', $detail);
  144. if(is_mobile()){
  145. return view('qiye@/finance/add_invoice');
  146. }
  147. return view('edit');
  148. }
  149. if(is_mobile()){
  150. return view('qiye@/finance/add_invoice');
  151. }
  152. return view();
  153. }
  154. }
  155. /**
  156. * 查看
  157. */
  158. public function view($id)
  159. {
  160. $detail = $this->model->getById($id);
  161. if (!empty($detail)) {
  162. $other_file_array = Db::name('File')->where('id','in',$detail['other_file_ids'])->select();
  163. $detail['other_file_array'] = $other_file_array;
  164. if($detail['open_status']>0){
  165. $detail['open_admin_name'] = Db::name('Admin')->where('id','=',$detail['open_admin_id'])->value('name');
  166. }
  167. View::assign('detail', $detail);
  168. View::assign('create_user', get_admin($detail['admin_id']));
  169. if(is_mobile()){
  170. return view('qiye@/finance/view_invoice');
  171. }
  172. return view();
  173. }
  174. else{
  175. return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
  176. }
  177. }
  178. /**
  179. * 删除
  180. */
  181. public function del()
  182. {
  183. $param = get_params();
  184. $id = isset($param['id']) ? $param['id'] : 0;
  185. if (request()->isDelete()) {
  186. $this->model->delById($id);
  187. } else {
  188. return to_assign(1, "错误的请求");
  189. }
  190. }
  191. //开票记录
  192. public function record()
  193. {
  194. $uid = $this->uid;
  195. $auth = isAuthInvoice($uid);
  196. if (request()->isAjax()) {
  197. $param = get_params();
  198. $tab = isset($param['tab']) ? $param['tab'] : 0;
  199. $where = [];
  200. $whereOr = [];
  201. $where[]=['delete_time','=',0];
  202. $where[]=['check_status','=',2];
  203. $where[]=['invoice_type','>',0];
  204. if($auth == 0){
  205. $dids_a = get_leader_departments($uid);
  206. $dids_b = get_role_departments($uid);
  207. $dids = array_merge($dids_a, $dids_b);
  208. if(!empty($dids)){
  209. $whereOr[] = ['did','in',$dids];
  210. }
  211. }
  212. if($tab == 0){
  213. //正常的
  214. $where[] = ['open_status', '<', 2];
  215. }
  216. if($tab == 1){
  217. //已作废的
  218. $where[] = ['open_status', '=', 2];
  219. }
  220. //按时间检索
  221. if (!empty($param['diff_time'])) {
  222. $diff_time =explode('~', $param['diff_time']);
  223. $where[] = ['open_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1].' 23:59:59'))]];
  224. }
  225. if (isset($param['open_status']) && $param['open_status'] != "") {
  226. $where[] = ['open_status', '=', $param['open_status']];
  227. }
  228. $list = $this->model->datalist($param,$where,$whereOr);
  229. $amount = $this->model::where($where)->where(function ($query) use($whereOr) {
  230. if (!empty($whereOr)){
  231. $query->whereOr($whereOr);
  232. }
  233. })->sum('amount');
  234. $totalRow['amount'] = sprintf("%.2f",$amount);
  235. return table_assign(0, '', $list);
  236. } else {
  237. View::assign('authInvoice', $auth);
  238. return view();
  239. }
  240. }
  241. /**
  242. * 无发票回款列表
  243. */
  244. public function datalist_a()
  245. {
  246. $param = get_params();
  247. if (request()->isAjax()) {
  248. $uid=$this->uid;
  249. $where = array();
  250. $whereOr = array();
  251. $where[]=['delete_time','=',0];
  252. $where[]=['invoice_type','=',0];
  253. $whereOr[] = ['admin_id', '=', $this->uid];
  254. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
  255. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
  256. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
  257. $auth = isAuthInvoice($uid);
  258. if($auth == 0){
  259. $dids_a = get_leader_departments($uid);
  260. $dids_b = get_role_departments($uid);
  261. $dids = array_merge($dids_a, $dids_b);
  262. if(!empty($dids)){
  263. $whereOr[] = ['did','in',$dids];
  264. }
  265. }
  266. //按时间检索
  267. if (!empty($param['diff_time'])) {
  268. $diff_time =explode('~', $param['diff_time']);
  269. $where[] = ['enter_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1].' 23:59:59'))]];
  270. }
  271. if (isset($param['enter_status']) && $param['enter_status'] != "") {
  272. $where[] = ['enter_status', '=', $param['enter_status']];
  273. }
  274. if (isset($param['check_status']) && $param['check_status'] != "") {
  275. $where[] = ['check_status', '=', $param['check_status']];
  276. }
  277. $list = $this->model->datalist($param,$where,$whereOr);
  278. return table_assign(0, '', $list);
  279. }
  280. else{
  281. View::assign('auth', isAuthIncome($this->uid));
  282. return view();
  283. }
  284. }
  285. /**
  286. * 无发票添加/编辑
  287. */
  288. public function add_a()
  289. {
  290. $param = get_params();
  291. if (request()->isAjax()) {
  292. $param['admin_id'] = $this->uid;
  293. $param['did'] = $this->did;
  294. if (!empty($param['id']) && $param['id'] > 0) {
  295. try {
  296. validate(InvoiceValidate::class)->scene('edit')->check($param);
  297. } catch (ValidateException $e) {
  298. // 验证失败 输出错误信息
  299. return to_assign(1, $e->getError());
  300. }
  301. $this->model->edit($param);
  302. } else {
  303. try {
  304. validate(InvoiceValidate::class)->scene('add')->check($param);
  305. } catch (ValidateException $e) {
  306. // 验证失败 输出错误信息
  307. return to_assign(1, $e->getError());
  308. }
  309. $this->model->add($param);
  310. }
  311. }else{
  312. $id = isset($param['id']) ? $param['id'] : 0;
  313. if ($id>0) {
  314. $detail = $this->model->getById($id);
  315. View::assign('detail', $detail);
  316. if(is_mobile()){
  317. return view('qiye@/finance/add_invoice_a');
  318. }
  319. return view('edit_a');
  320. }
  321. if(is_mobile()){
  322. return view('qiye@/finance/add_invoice_a');
  323. }
  324. return view();
  325. }
  326. }
  327. /**
  328. * 无发票查看
  329. */
  330. public function view_a($id)
  331. {
  332. $detail = $this->model->getById($id);
  333. if (!empty($detail)) {
  334. $detail['subject'] = Db::name('Enterprise')->where(['id' =>$detail['invoice_subject']])->value('title');
  335. $other_file_array = Db::name('File')->where('id','in',$detail['other_file_ids'])->select();
  336. $detail['other_file_array'] = $other_file_array;
  337. if($detail['open_status']>0){
  338. $detail['open_admin_name'] = Db::name('Admin')->where('id','=',$detail['open_admin_id'])->value('name');
  339. }
  340. View::assign('detail', $detail);
  341. View::assign('create_user', get_admin($detail['admin_id']));
  342. if(is_mobile()){
  343. return view('qiye@/finance/view_invoice_a');
  344. }
  345. return view();
  346. }
  347. else{
  348. return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
  349. }
  350. }
  351. /**
  352. * 删除
  353. */
  354. public function del_a($id)
  355. {
  356. if (request()->isDelete()) {
  357. $this->model->delById($id);
  358. } else {
  359. return to_assign(1, "错误的请求");
  360. }
  361. }
  362. }