123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- <?php
- Doo::loadCore ( 'db/DooModel' );
- /**
- * 发票培训班相关信息及其操作业务逻辑
- * @author CP.
- * @version 1.0
- * @namespace invoice
- * @package invoiceModel
- */
- class invoiceTraining extends DooModel {
- public $itid;
- public $status;
- public $submitStatus;
- public $trainName;
- public $cid;
- public $categoryName;
- public $creator;
- public $trainDate;
- public $invoiceTotal;
- public $invoiceTotalAmount;
- public $invoiceArriveAmount;
- public $arriveSchedule;
- public $creatorDate;
- public $_table = 'CLD_invoiceTraining';
- public $_primarykey = 'itid';
- public $_fields = array (
- 'itid',
- 'status',
- 'submitStatus',
- 'trainName',
- 'cid',
- 'categoryName',
- 'creator',
- 'trainDate',
- 'invoiceTotal',
- 'invoiceTotalAmount',
- 'invoiceArriveAmount',
- 'arriveSchedule',
- 'creatorDate'
- );
-
- /**
- * 添加一个培训班
- * @param array $item 培训班相关数据
- * @return number 返回培训班ID
- */
- public function addInvoiceTraining($item = array()) {
- $itid = 0;
- if (is_array ( $item ) && ! empty ( $item )) {
- foreach ( $item as $key => $value ) {
- $this->$key = $value;
- }
- $itid = $this->insert ();
- }
- return $itid;
- }
- function getInvoiceTrainStatistics($itid=0) {
-
- $itidCondition=' and trainId=NULL ';
- if (!empty($itid))
- $itidCondition=' and trainId in ('.$itid.') ';
-
- $sql = 'select sum(invoicePrice) as invoicePrice ,trainId
- from CLD_invoice
- where status=2 and printStatus=1 and (untreadStatus =0 or untreadStatus=3) '.$itidCondition.'
- GROUP BY status';
- $query = Doo::db ()->query ( $sql );
- $result = $query->fetchAll ();
-
- if (! empty ( $result ))
- $detail = array (
- 'invoicePrice' => $result [0] ['invoicePrice']
- );
- else
- $detail = array (
- 'invoicePrice' => 0
- );
- // print_r($result);
- $itidCondition=' and a.trainId=NULL ';
- if (!empty($itid))
- $itidCondition=' and a.trainId in ('.$itid.') ';
- $sql = 'select sum(b.receivablesPrice) as receivablesPrice ,a.trainId,count(*) as count
- from CLD_invoice as a left join CLD_invoiceReceivables as b on find_in_set(a.irid,b.irid)
- where a.status=2 and a.printStatus=1 and (a.untreadStatus =0 or a.untreadStatus=3) and a.irid!="" '.$itidCondition.'
- GROUP BY a.status';
- $query = Doo::db ()->query ( $sql );
- $result = $query->fetchAll ();
-
- if (! empty ( $result )) {
- $detail += array (
- 'receivablesPrice' => $result [0] ['receivablesPrice']
- );
- $detail += array (
- 'rPrice' => $detail ['invoicePrice'] - $result [0] ['receivablesPrice']
- );
- } else {
- $detail += array (
- 'receivablesPrice' => 0
- );
- $detail += array (
- 'rPrice' => $detail ['invoicePrice']
- );
- }
- return $detail;
- }
- function getInvoiceTrainingByTodo($select = "", $cid = 0,$sid=0) {
- Doo::loadModel ( 'staff' );
- $staff = new staff ();
- Doo::loadModel ( 'L_category' );
- $lCategory = new L_category ();
-
- $condition = array (
- 'where' => "(status= 0 or status=1) and ( cid=" . $cid." or creator=".$sid." )",
- 'limit' => 8,
- 'asArray' => TRUE
- );
- if (! empty ( $select ))
- $condition += array (
- 'select' => $select
- );
-
- $list = $this->find ( $condition );
-
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- $itid = array ();
- foreach ( $list as $key => $value ) {
- $list [$key] ['trainingKey'] = $XDeode->encode ( $value ['itid'] );
- $detail = $staff->getStaffBySid ( $value ['creator'] );
- $list [$key] ['staff'] = $detail;
- $detail = $lCategory->getCategoryById ( $value ['cid'] );
- $list [$key] ['category'] = $detail;
- array_push ( $itid, $value ['itid'] );
- }
-
- // 获得开票金额合计 入账金额合计 入账完成度
- Doo::loadModel ( 'invoice' );
- $invoice = new invoice ();
-
- $invoiceList=$invoiceRecelvablesList=array();
- if (! empty ( $itid )) {
- $itidSql = implode ( ',', $itid );
- $invoiceList = $invoice->sumOfinvoiceTrain ( $itidSql );
- $invoiceRecelvablesList = $invoice->sumOfInvoiceRecelvablesTrain ( $itidSql );
- }
- // print_r($invoiceRecelvablesList);
-
- foreach ( $list as $key => $value ) {
- foreach ( $invoiceList as $k => $v ) {
- if ($value ['itid'] == $v ['trainId']) {
- $list [$key] ['invoiceTotalAmount'] = $v ['invoicePrice'];
- break;
- }
- }
- foreach ( $invoiceRecelvablesList as $i => $o ) {
- if ($value ['itid'] == $o ['trainId']) {
- $list [$key] ['invoiceArriveAmount'] = $o ['receivablesPrice'];
- $list [$key] ['arriveSchedule'] = "0";
- if ($value ['invoiceTotal'] != 0)
- $list [$key] ['arriveSchedule'] = round ( $o ['count'] / $value ['invoiceTotal'] * 100, 2 );
-
- break;
- }
- }
- }
-
- return $list;
- }
-
- /**
- * 根据参数字段更新相应字段(主键ID必须传)
- * @param array $item 相关需要更新的字段信息
- * @return number 返回发票ID
- */
- public function setInvoiceTrainByCondition($item = array(), $itid = "") {
- $lid = 0;
-
- if (is_array ( $item ) && ! empty ( $item )) {
- foreach ( $item as $key => $value ) {
- $this->$key = $value;
- }
-
- if (! empty ( $isid )) {
- $condition = array (
- 'where' => "itid in (" . $itid . ")",
- 'asArray' => TRUE
- );
- $this->update ( $condition );
- } else
- $lid = $this->update ();
- }
- return $lid;
- }
-
- /**
- * 根据状态获取培训班
- * @param number $status
- */
- function getInvoiceTrainingByStatus($status = 0, $select = "", $cid = 0,$sid=0) {
- Doo::loadModel ( 'staff' );
- $staff = new staff ();
- Doo::loadModel ( 'L_category' );
- $lCategory = new L_category ();
-
- $condition = array (
- 'where' => "status= '" . $status . "' and (cid=" . $cid." or creator=".$sid." )",
- 'limit' => 8,
- 'asArray' => TRUE
- );
- if (! empty ( $select ))
- $condition += array (
- 'select' => $select
- );
-
- $list = $this->find ( $condition );
-
- foreach ( $list as $key => $value ) {
- $detail = $staff->getStaffBySid ( $value ['creator'] );
- $list [$key] ['staff'] = $detail;
- $detail = $lCategory->getCategoryById ( $value ['cid'] );
- $list [$key] ['category'] = $detail;
- }
-
- return $list;
- }
-
- /**
- * 根据ID获得培训班
- * @param number $itid
- */
- function getInvoiceTrainingByItid($itid = 0) {
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- $itid = $XDeode->decode ( $itid );
-
- $detail = array ();
- if (! empty ( $itid ) && is_numeric ( $itid )) {
- $detail = $this->getOne ( array (
- 'where' => " itid=" . $itid,
- 'asArray' => TRUE
- ) );
- }
- $detail ['trainingKey'] = '';
- if (! empty ( $detail ))
- $detail ['trainingKey'] = $XDeode->encode ( $detail ['itid'] );
-
- return $detail;
- }
-
- /**
- * 根据ID删除数据
- * @param number $itid
- */
- function delInvoiceTrainingByItid($itid = 0) {
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- $itid = $XDeode->decode ( $itid );
- if (! empty ( $itid ) && is_numeric ( $itid ))
- $this->delete ( array (
- 'where' => 'itid=' . $itid
- ) );
- }
- }
- ?>
|