You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

248 rivejä
8.8 KiB

  1. <?php
  2. namespace backend\modules\motorcade\controllers;
  3. use backend\modules\motorcade\models\BusOrderFinance;
  4. use common\components\zPhpExcel;
  5. use Yii;
  6. use backend\modules\motorcade\models\BusOrder;
  7. use backend\modules\motorcade\models\searchOrder;
  8. use yii\db\Exception;
  9. use yii\helpers\Json;
  10. use yii\web\NotFoundHttpException;
  11. use yii\filters\VerbFilter;
  12. /**
  13. * FinanceController implements the CRUD actions for BusOrder model.
  14. */
  15. class FinanceController extends BaseController
  16. {
  17. public $layout = "@backend/modules/motorcade/views/layouts/iframe_new";
  18. /**
  19. * @inheritdoc
  20. */
  21. public function behaviors()
  22. {
  23. return [
  24. 'verbs' => [
  25. 'class' => VerbFilter::className(),
  26. 'actions' => [
  27. 'delete' => ['POST'],
  28. ],
  29. ],
  30. ];
  31. }
  32. /**
  33. * Lists all BusOrder models.
  34. * @return mixed
  35. */
  36. public function actionIncome()
  37. {
  38. $searchModel = new searchOrder();
  39. $searchModel->date_type = 1;
  40. $time = strtotime('-1 months');
  41. $searchModel->date_from = date('Y-m-01', $time);
  42. $searchModel->date_to = date('Y-m-t', $time);
  43. $search = Yii::$app->request->queryParams;
  44. $dataProvider = $searchModel->search($search);
  45. if (Yii::$app->request->isPjax) {
  46. return $this->renderPartial('index', [
  47. 'searchModel' => $searchModel,
  48. 'dataProvider' => $dataProvider,
  49. ]);
  50. } else {
  51. return $this->render('index', [
  52. 'searchModel' => $searchModel,
  53. 'dataProvider' => $dataProvider,
  54. ]);
  55. }
  56. }
  57. /**
  58. * 外部调车应付记录
  59. *
  60. * @return string
  61. *
  62. * @author wangxj
  63. */
  64. public function actionOutcome()
  65. {
  66. $searchModel = new searchOrder();
  67. $searchModel->date_type = 1;
  68. $time = strtotime('-1 months');
  69. $searchModel->date_from = date('Y-m-01', $time);
  70. $searchModel->date_to = date('Y-m-t', $time);
  71. $search = Yii::$app->request->queryParams;
  72. $searchModel->send_type = 1;
  73. $dataProvider = $searchModel->search($search);
  74. if (Yii::$app->request->isPjax) {
  75. return $this->renderPartial('index', [
  76. 'searchModel' => $searchModel,
  77. 'dataProvider' => $dataProvider,
  78. ]);
  79. } else {
  80. return $this->render('index', [
  81. 'searchModel' => $searchModel,
  82. 'dataProvider' => $dataProvider,
  83. ]);
  84. }
  85. }
  86. /**
  87. * Finds the BusOrder model based on its primary key value.
  88. * If the model is not found, a 404 HTTP exception will be thrown.
  89. * @param integer $id
  90. * @return BusOrder the loaded model
  91. * @throws NotFoundHttpException if the model cannot be found
  92. */
  93. protected function findModel($id)
  94. {
  95. if (($model = BusOrder::findOne($id)) !== null) {
  96. return $model;
  97. } else {
  98. throw new NotFoundHttpException('The requested page does not exist.');
  99. }
  100. }
  101. /**
  102. * User: wangxj
  103. *
  104. * 开关账操作
  105. *
  106. * 关账的时候要同步一次出车任务中run_id不为0的数据
  107. *
  108. * @param integer $send_type 应收 应付
  109. * @param $type ['open', 'close']
  110. */
  111. public function actionCondom()
  112. {
  113. $searchModel = new searchOrder();
  114. $search = Yii::$app->request->post();
  115. $searchModel->search($search);
  116. $type = $_REQUEST['type'];
  117. $send_type = $_REQUEST['send_type'];
  118. $searchModel->send_type = $send_type;
  119. $tran = Yii::$app->db->beginTransaction();
  120. $rows = 0;
  121. try{
  122. $rows = $searchModel->condomAction($type);
  123. }catch (Exception $e){
  124. // $tran->rollBack();
  125. }
  126. if ($rows) {
  127. $tran->commit();
  128. $result = ['code' => 0, 'msg' => ($type == 'open' ? '取消关账' : '关账') . '成功!'];
  129. } else {
  130. $tran->rollBack();
  131. $result = ['code' => 1, 'msg' => ($type == 'open' ? '取消关账' : '关账') . '失败!'];
  132. }
  133. return Json::encode($result);
  134. }
  135. /**
  136. * User: wangxj
  137. *
  138. * 应收管理 导出订单
  139. *
  140. */
  141. public function actionExport()
  142. {
  143. ini_set("memory_limit", "-1");
  144. $objPHPExcel = new zPhpExcel(); //实例化PHPExcel类
  145. $objSheet = $objPHPExcel->getActiveSheet(); //获取当前活动sheet的操作对象
  146. $searchModel = new searchOrder();
  147. $search = Yii::$app->request->queryParams;
  148. $dataProvider = $searchModel->search($search);
  149. $dataProvider-> pagination = false;
  150. $data = $dataProvider->getModels();
  151. //出车 / 收车日期{开始日期}-{结束日期} {客户名称} {5种结算状态}订单
  152. $client = '';
  153. $status = $searchModel->end_status === '' ? '' : (' ' . searchOrder::$finance_type_array[$searchModel->end_status]);
  154. $objPHPExcel->file_name = ($searchModel->date_type == 1 ? '出车日期' : '收车日期') . ' ' . ($searchModel->date_from . '-' . $searchModel->date_to) . ' ' . $client . ' ' . $status;
  155. $objSheet->setTitle('订单列表');
  156. $order_sort = ['id', 'bus_number', 'create_time', 'depart_name', 'itinerary_name', 'bus_no', 'run_bus_id', 'run_date', 'date_end', 'bus_cost', 'bus_cost_id', 'send_cost', 'pay_type_name', 'end_status_name'];
  157. //设置表头
  158. $a_k = range('A', 'N');
  159. foreach ($a_k as $key => $item) {
  160. $objSheet->setCellValue($item . '1', $searchModel->getAttributeLabel($order_sort[$key]));
  161. }
  162. foreach ($data as $key => $datum) {
  163. foreach ($a_k as $index => $item) {
  164. if ($item == 'A')
  165. $objSheet->setCellValue($item . ($key + 2), $key + 1);
  166. else
  167. $objSheet->setCellValue($item . ($key + 2),
  168. $order_sort[$index] == 'run_bus_id' ? ($datum->$order_sort[$index] == 0 ? '-' : $datum->$order_sort[$index])
  169. : $datum->$order_sort[$index]);
  170. }
  171. }
  172. //设置宽度
  173. $objPHPExcel->setColumnSize(range('C', 'N'), [20, 20, 55, 12, 10, 12, 10, 10, 12, 12,12,12,12]);
  174. $objPHPExcel->output();
  175. }
  176. /**
  177. * User: wangxj
  178. *
  179. * 生成对账单,BusOrderFinance
  180. *
  181. */
  182. public function actionGenerateOrderFinance()
  183. {
  184. $searchModel = new searchOrder();
  185. $search = Yii::$app->request->post();
  186. $searchModel->search($search);
  187. $end_attr = $searchModel->send_type ? 'outcome_end_status' : 'end_status';
  188. if ($searchModel->$end_attr != 1) {
  189. $result = ['code' => 1, 'msg' => '请切换已关账的出车订单!'];
  190. } else {
  191. //客户为单位,所需数据
  192. $data = $searchModel->getOrderFinanceOrder();
  193. if (count($data) > 0) {
  194. $transaction = Yii::$app->db->beginTransaction();
  195. try {
  196. foreach ($data as $datum) {
  197. /* @var $datum \backend\modules\motorcade\models\searchOrder */
  198. $orderFinance = new BusOrderFinance();
  199. $orderFinance->DATE_FROM = $searchModel->date_from;
  200. $orderFinance->DATE_TO = $searchModel->date_to;
  201. $orderFinance->USE_BUS_ORG_ID = $datum->use_bus_org_id;
  202. $orderFinance->BUS_COST = $searchModel->send_type ? $datum->send_cost : $datum->bus_cost;
  203. $orderFinance->FINANCE_TYPE = $searchModel->send_type ? 1 : 0;
  204. $orderFinance->BUS_ORDER_COUNT = $datum->bus_order_count;
  205. if ($orderFinance->save()) {
  206. if ($orderFinance->FINANCE_TYPE == 1) {
  207. BusOrder::updateAll(['outcome_end_status' => BusOrder::STATUS_END_WAITING_CONFIRM, 'bus_order_outcome_finance' => $orderFinance->ID],
  208. 'id in (' . $datum->bus_ids . ')');
  209. } else {
  210. BusOrder::updateAll(['end_status' => BusOrder::STATUS_END_WAITING_CONFIRM, 'bus_order_finance' => $orderFinance->ID],
  211. 'id in (' . $datum->bus_ids . ')');
  212. }
  213. }
  214. }
  215. $transaction->commit();
  216. $result = ['code' => 0, 'msg' => '生成对账单成功!'];
  217. } catch (Exception $e) {
  218. $transaction->rollBack();
  219. $result = ['code' => 1, 'msg' => '生成对账单失败!'];
  220. }
  221. } else {
  222. $result = ['code' => 1, 'msg' => '无数据生成对账单!'];
  223. }
  224. }
  225. return Json::encode($result);
  226. }
  227. }