$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(b.irid,a.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; } /** * 根据办事处获得结算完成培训班 * @param number $SStatus * @return string */ function getInvoiceTrainBySettlementStatus($SStatus = 0, $cid = 0,$bindReceipt) { $condition = array ( 'where' => " settlementStatus=" . $SStatus . ' and cid=' . $cid. ' and bindReceipt=' . $bindReceipt, 'asArray' => TRUE ); $list = $this->find ( $condition ); Doo::loadClass ( 'XDeode' ); $XDeode = new XDeode ( 5 ); foreach ( $list as $key => $value ) { $list [$key] ['itidKey'] = $XDeode->encode ( $value ['itid'] ); } return $list; } /** * 获得办事处下的培训班 */ function getInvoiceTrainingByCid($cid = 0) { $condition = array ( 'where' => " cid=" . $cid, 'asArray' => TRUE ); $list = $this->find ( $condition ); Doo::loadClass ( 'XDeode' ); $XDeode = new XDeode ( 5 ); foreach ( $list as $key => $value ) { $list [$key] ['itidKey'] = $XDeode->encode ( $value ['itid'] ); } return $list; } 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 in (" . $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 ) { $countInvoice = $invoice->getInvoiceByTrainingCount ( $value ['itid'] ); $value ['invoiceTotal'] = $countInvoice; $list [$key] ['invoiceTotal'] = $countInvoice; 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 ( $list [$key] ['invoiceArriveAmount'] / $list [$key] ['invoiceTotalAmount'] * 100, 2 ); // $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 ( $itid )) { $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 in(" . $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 ) { $countInvoice = $invoice->getInvoiceByTrainingCount ( $value ['itid'] ); $value ['invoiceTotal'] = $countInvoice; $list [$key] ['invoiceTotal'] = $countInvoice; 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 ( $list [$key] ['invoiceArriveAmount'] / $list [$key] ['invoiceTotalAmount'] * 100, 2 ); // $list [$key] ['arriveSchedule'] = round ( $o ['count'] / $value ['invoiceTotal'] * 100, 2 ); } break; } } } return $list; } /** * 根据ID获得培训班 * @param number $itid */ function getInvoiceTrainingByItid($itid = 0) { Doo::loadClass ( 'XDeode' ); $XDeode = new XDeode ( 5 ); if (! is_numeric ( $itid )) $itid = $XDeode->decode ( $itid ); $detail = array (); if (! empty ( $itid ) && is_numeric ( $itid )) { $detail = $this->getOne ( array ( 'where' => " itid=" . $itid, 'asArray' => TRUE ) ); } $detail ['trainingKey'] = ''; $detail ['RIAmount']=$detail ['invoiceArriveAmount']=$detail ['invoiceTotalAmount']=0; if (! empty ( $detail )) { Doo::loadModel ( 'L_category' ); $lCategory = new L_category (); Doo::loadModel ( 'staff' ); $staff = new staff (); $cateList = $lCategory->getCategoryById ( $detail ['cid'] ); $itid = $detail ['itid']; $detail ['trainingKey'] = $XDeode->encode ( $detail ['itid'] ); $staffdetail = $staff->getStaffBySid ( $detail ['creator'] ); $detail ['staff'] = $staffdetail; $catedetail = $lCategory->getCategoryById ( $detail ['cid'] ); $detail ['category'] = $catedetail; // 获得开票金额合计 入账金额合计 入账完成度 Doo::loadModel ( 'invoice' ); $invoice = new invoice (); $invoiceList=$companyList=$RIList = $invoiceRecelvablesList = array (); if (! empty ( $itid )) { $itidSql = $itid; //培训班收款 $invoiceList = $invoice->sumOfinvoiceTrain ( $itidSql ); $invoiceRecelvablesList = $invoice->sumOfInvoiceRecelvablesTrain ( $itidSql ); //公司收款 $companyList = $invoice->sumOfInvoiceRecelvablesCompany ( $itidSql ); //获得办事处已收款 $RIList=$invoice->sumOfInvoiceByItid($itid); } //print_r($invoiceRecelvablesList); $countInvoice = $invoice->getInvoiceByTrainingCount ( $detail ['itid'] ); $detail ['invoiceTotal'] = $countInvoice; foreach ( $invoiceList as $k => $v ) { if ($detail ['itid'] == $v ['trainId']) { $detail ['invoiceTotalAmount'] = $v ['invoicePrice']; break; } } foreach ( $invoiceRecelvablesList as $i => $o ) { if ($detail['itid'] == $o ['trainId']) { $detail ['invoiceArriveAmount'] = $o ['receivablesPrice']; $detail ['arriveSchedule'] = 0; if ($detail ['invoiceTotal'] != 0) { $detail ['arriveSchedule'] = round ( $detail ['invoiceArriveAmount'] / $detail ['invoiceTotalAmount'] * 100, 2 ); } break; } } //办事处已收款 foreach ($RIList as $key=>$value){ if ($detail ['itid'] == $value ['trainId']) { $detail ['RIAmount'] = $value ['invoicePrice']; break; } } //公司已收款 $detail ['invoiceCompanyAmount']=0; foreach ($companyList as $key=>$value){ if ($detail ['itid'] == $value ['trainId']) { $detail ['invoiceCompanyAmount'] = $value ['receivablesPrice']; break; } } } //echo var_dump($detail ['invoiceTotalAmount'] ) ; //print_r($detail); 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 ) ); // 删除培训班下的发票 Doo::loadModel ( 'invoiceStore' ); $invoiceStore = new invoiceStore (); $invoiceStore->delete ( array ( 'where' => 'trainId=' . $itid ) ); } /** * 获得某办事处未完成的培训班 * @return string */ function getInvoiceTrainingByUnfinished($cid = 0) { $condition = array ( 'where' => "(status= 0 or status=1) and cid=" . $cid, 'asArray' => true ); $list = $this->find ( $condition ); Doo::loadClass ( 'XDeode' ); $XDeode = new XDeode ( 5 ); foreach ( $list as $key => $value ) { $list [$key] ['itidKey'] = $XDeode->encode ( $value ['itid'] ); } return $list; } /** * 获得所有培训班 */ function getInvoiceTrainingBySubmitStatus() { $condition = array ( 'where' => "submitStatus=1", 'asArray' => TRUE ); $list = $this->find ( $condition ); Doo::loadClass ( 'XDeode' ); $XDeode = new XDeode ( 5 ); foreach ( $list as $key => $value ) { $list [$key] ['itidKey'] = $XDeode->encode ( $value ['itid'] ); } return $list; } } ?>