123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540 |
- <?php
- Doo::loadCore ( 'db/DooModel' );
- /**
- * 发票培训班相关信息及其操作业务逻辑
- * @author CP.
- * @version 1.0
- * @namespace invoice
- * @package invoiceModel
- */
- class invoiceTraining extends DooModel {
- public $itid;
- public $bindReceipt;
- 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 $settlementStatus;
- public $_table = 'CLD_invoiceTraining';
- public $_primarykey = 'itid';
- public $_fields = array (
- 'itid',
- 'bindReceipt',
- 'status',
- 'submitStatus',
- 'trainName',
- 'cid',
- 'categoryName',
- 'creator',
- 'trainDate',
- 'invoiceTotal',
- 'invoiceTotalAmount',
- 'invoiceArriveAmount',
- 'arriveSchedule',
- 'settlementStatus',
- '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(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 findAll($condition=array()){
- $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,
- 'desc'=>'itid',
- '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 ();
- $itidSum=array();
- if (! empty ( $itid )) {
- $itidSql = implode ( ',', $itid );
- $invoiceList = $invoice->sumOfinvoiceTrain ( $itidSql );
-
-
- // 1.所有培训班发票 收款合计
- $invoiceRecelvablesList = $invoice->InvoiceTrainIncomesPrice($itid);
- //print_r($invoiceRecelvablesList);
- //$invoiceRecelvablesList = $invoice->sumOfInvoiceRecelvablesTrain ( $itidSql );
-
- // 收款有多个发票绑定,导致收款金额没有统计--TODO
- // 获得收款扩展部分的金额
- // id
- $iidList=$invoice->getInvoiceByTrain($itidSql);
- foreach ($iidList as $key=>$value){
- $idData=explode(",", $value['iid']);
- $sum=0;
- foreach ($idData as $item){
-
- $sum+=$invoice->getTrainRP($item);
-
- }
- //
- $itidSum[$value['trainId']]=$sum;
- }
-
- }
- //print_r($iidList);
- // print_r($invoiceRecelvablesList);
- // print_r($itidSum);
-
- 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] ['invoiceArriveAmount']+=$itidSum[$value ['itid']];
- $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->InvoiceTrainIncomesPrice($itid);
- //$invoiceRecelvablesList = $invoice->sumOfInvoiceRecelvablesTrain ( $itidSql );
-
- }
- // print_r($invoiceRecelvablesList);
- //print_r($itidSum);
-
- 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
- ) );
- }
-
- if (! empty ( $detail )) {
- $detail ['trainingKey'] = '';
- $detail ['invoiceArriveAmount']=$detail ['invoiceCompanyAmount']=$detail ['RIAmount']=$detail ['invoiceArriveAmount']=$detail ['invoiceTotalAmount']=0;
-
- 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 ();
- //echo $itid;
- $invoiceList=$companyList=$RIList = $invoiceRecelvablesList = array ();
- if (! empty ( $itid )) {
- $itidSql = $itid;
- //培训班收款
- $invoiceList = $invoice->sumOfinvoiceTrain ( $itidSql );
- $invoiceRecelvablesList = $invoice->sumOfInvoiceRecelvablesTrain ( $itidSql );
- //公司收款--新的入账--fix
- $companyList = $invoice->sumOfInvoiceRecelvablesCompany ( $itidSql );
- //获得办事处已收款
- $RIList=$invoice->sumOfInvoiceByItid($itid);
- //print_r($RIList);
- }
- //print_r($invoiceRecelvablesList);
-
- //入账金额-培训班
- Doo::loadModel ( 'bill' );
- $bill = new bill ();
- $billPrice=$bill->find(array (
- 'select'=>'sum(price) as price',
- 'where' => 'trainId='. $itid ,
- 'orderby' => 'trainId',
- 'asArray' => true
- ));
- $detail ['billPrice']=0;
- if (!empty($billPrice)){
- if (!empty($billPrice[0]['price'])){
- $detail ['billPrice']=$billPrice[0]['price'];
- }
- }
-
- $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 ['invoiceArriveAmount']!=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;
- }
- }
-
- $detail ['invoiceCompanyAmountM']=sprintf ( "%.2f", $detail ['invoiceCompanyAmount'] );
- $detail ['invoiceArriveAmountM']=sprintf ( "%.2f", $detail ['invoiceArriveAmount'] );
-
- }
-
-
- //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;
- }
- }
- ?>
|