123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603 |
- <?php
- Doo::loadCore ( 'db/DooModel' );
- class receipt extends DooModel {
- public $rid;
- public $accountItem;
- public $loanItem;
- public $staff;
- public $sum;
- public $date;
- public $pastDate;
- public $executeDate;
- public $loanDate;
- public $cid;
- public $status;
- public $Rtype;
- public $isBK;
- public $loanSum;
- public $loanRid;
- public $reviseDetail;
- public $revisePrice;
- public $receiptOrder;
- public $verify;
- public $verifyStaff;
- public $executeCopy;
- public $executeStaff;
- public $verifyBreakup;
- public $nowStaff;
- public $explanation;
- public $implementOpinions;
- public $notice;
- public $amount;
- public $remittanceName;
- public $bankName;
- public $bankNumber;
- public $coupletNumber;
- public $remittanceBankType;
- public $trainId;
- public $trainLoanRid;
- public $invoiceTrainId;
- public $paidStatus;
- public $statusTrain;
- public $receiptClass;
- public $itinerary;
- public $_table = 'CLD_receipt';
- public $_primarykey = 'rid';
- public $_fields = array (
- 'aid',
- 'accountItem',
- 'staff',
- 'sum',
- 'date',
- 'pastDate',
- 'cid',
- 'status',
- 'reviseDetail',
- 'revisePrice',
- 'verify',
- 'verifyStaff',
- 'nowStaff',
- 'receiptOrder',
- 'explanation',
- 'notice',
- 'Rtype',
- 'loanItem',
- 'loanRid',
- 'loanSum',
- 'implementOpinions',
- 'isBK',
- 'executeCopy',
- 'executeStaff',
- 'verifyBreakup',
- 'executeDate',
- 'amount',
- 'loanDate',
- 'remittanceName',
- 'bankName',
- 'bankNumber',
- 'coupletNumber',
- 'remittanceBankType',
- 'trainId',
- 'trainLoanRid',
- 'invoiceTrainId' ,
- 'paidStatus',
- 'statusTrain',
- 'receiptClass',
- 'itinerary',
- );
-
-
- /*
- $this->query($sql, array_merge( $opt['param'], $where_values));
-
- */
-
-
-
- /**
- * 获得培训班结算未收款
- */
- function getReceiptTrainByPaid($un=0,$limit=5,$cid=''){
- if (empty($cid)){
- return array();
- }
- $sql = "select b.* ,a.invoiceTrainId,a.rid,a.executeDate
- from " . $this->_table . " as a left JOIN CLD_receiptTraining as b on (a.trainId=b.rtid)
- where a.status not in (3,4,5) and a.Rtype=3 and a.trainId!=0 and invoiceTrainId!=0 and a.cid in (".$cid.") and paidStatus=".$un." limit ".$limit;
- $query = Doo::db ()->query ( $sql );
- $result = $query->fetchAll ();
- Doo::loadModel ( 'invoiceTraining' );
- $invoiceTraining = new invoiceTraining ();
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 7 );
- Doo::loadModel ( 'RItem' );
- $RItem = new RItem ();
- Doo::loadModel ( 'RILecturer' );
- $RILecturer = new RILecturer ();
- Doo::loadModel ( 'accountItem' );
- $accountItem = new accountItem ();
- foreach ($result as $key=>$value){
- $result[$key]['ridKey']= $XDeode->encode ( $value ['rid'] );
- $result[$key]['iTrain']=$invoiceTraining->getInvoiceTrainingByItid ( $value ['invoiceTrainId'] );
- $result[$key]['iTrain']['receivablesAmount']=sprintf ( "%.2f",$result[$key]['iTrain']['invoiceTotalAmount']-$result[$key]['iTrain']['invoiceArriveAmount']);
- $RItemList = $RItem->getRItemByRid ( $value ['rid'] );
- $RILecturerList = $RILecturer->getRILecturerByRid ( $value ['rid'] );
- // 支出项金额详情
- $expendList= $accountItem->getTrainingDetail ( $RItemList, $RILecturerList );
- $result[$key]['iTrain']['expendAmount']=sprintf ( "%.2f",$expendList['total']);
- $result[$key]['iTrain']['profit']= sprintf ( "%.2f",$result[$key]['iTrain']['invoiceTotalAmount']-$expendList['total']);
- }
- return $result;
- }
- /**
- * 获得所有培训班结算
- */
- function getReceiptTrainByPaidAll($un='',$cid='',$dateSql='',$limit='0,18',$cidString="",$where=""){
- $psSql='';
- if(!empty($un)){
- $psSql=" and paidStatus=".$un." ";
- }
- $cidSql="";
- if(!empty($cid)){
- $cidSql=" and a.cid=".$cid." ";
- }elseif(!empty($cidString)){
- $cidSql=" and a.cid in (".$cidString.") ";
- }else{
- return array();
- }
- $sql = "select b.* ,a.invoiceTrainId,a.rid
- from " . $this->_table . " as a left JOIN CLD_receiptTraining as b on (a.trainId=b.rtid)
- ".$where.$psSql.$cidSql.$dateSql." limit ".$limit;
- $query = Doo::db ()->query ( $sql );
- $result = $query->fetchAll ();
- Doo::loadModel ( 'invoiceTraining' );
- $invoiceTraining = new invoiceTraining ();
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 7 );
- Doo::loadModel ( 'RItem' );
- $RItem = new RItem ();
- Doo::loadModel ( 'RILecturer' );
- $RILecturer = new RILecturer ();
- Doo::loadModel ( 'accountItem' );
- $accountItem = new accountItem ();
- foreach ($result as $key=>$value){
- $result[$key]['ridKey']= $XDeode->encode ( $value ['rid'] );
- $result[$key]['iTrain']=$invoiceTraining->getInvoiceTrainingByItid ( $value ['invoiceTrainId'] );
- $result[$key]['iTrain']['receivablesAmount']=sprintf ( "%.2f",$result[$key]['iTrain']['invoiceTotalAmount']-$result[$key]['iTrain']['invoiceArriveAmount']);
- $RItemList = $RItem->getRItemByRid ( $value ['rid'] );
- $RILecturerList = $RILecturer->getRILecturerByRid ( $value ['rid'] );
- // 支出项金额详情
- $expendList= $accountItem->getTrainingDetail ( $RItemList, $RILecturerList );
- $result[$key]['iTrain']['expendAmount']=sprintf ( "%.2f",$expendList['total']);
- $result[$key]['iTrain']['profit']= sprintf ( "%.2f",$result[$key]['iTrain']['invoiceTotalAmount']-$expendList['total']);
- //利润
- $result[$key]['iTrain']['companyProfit']=sprintf ( "%.2f",$result[$key]['iTrain']['invoiceTotalAmount']*0.4);
- $result[$key]['iTrain']['categoryProfit']=sprintf ( "%.2f",$result[$key]['iTrain']['invoiceTotalAmount']*0.6);
- }
- return $result;
- }
- /**
- * 获得培训班结算的合计金额
- * @param string $itid 发票培训班ID
- */
- function getReceiptTrainSumByItid($sql=""){
- Doo::loadModel ( 'invoice' );
- $invoice = new invoice ();
- $query = Doo::db ()->query ( $sql );
- $result = $query->fetchAll ();
- //组合发票培训班ID
- $itidList = array ();$ridList=array();
- foreach ($result as $key=>$value){
- array_push ( $itidList, $value ['invoiceTrainId'] );
- array_push ( $ridList, $value ['rid'] );
- }
- $itidList = array_unique($itidList);
- $itidString=implode ( ',', $itidList );
- $ridList = array_unique($ridList);
- $ridString=implode ( ',', $ridList );
- //发票培训班ID-整合出开票金额合计-入账金额合计
- $invoiceList = $invoice->sumOfinvoiceTrain ( $itidString );//开票合计-开票收入
- $invoiceRecelvablesList = $invoice->sumOfInvoiceRecelvablesTrain ( $itidString );//入账合计-实际收入
- $invoiceTotalAmount=0;//开票金额合计
- $receivablesTotalAmount=0;//入账金额合计
- foreach ( $invoiceList as $k => $v ) {
- $invoiceTotalAmount+=$v ['invoicePrice'];
- }
- foreach ( $invoiceRecelvablesList as $i => $o ) {
- $receivablesTotalAmount+=$o ['receivablesPrice'];
- }
- //未收款
- $unReceivablesTotalAmount=sprintf ( "%.2f",$invoiceTotalAmount-$receivablesTotalAmount);
- //获得支出金额合计
- Doo::loadModel ( 'RItem' );
- $RItem = new RItem ();
- Doo::loadModel ( 'RILecturer' );
- $RILecturer = new RILecturer ();
- $RItemPrice=$RItem->getRItemPriceByRids($ridString);
- $RILecturerPrice=$RILecturer->getRILecturerPriceByRids($ridString);
- $payPrice=$RItemPrice+$RILecturerPrice;//支出金额合计
- $profit=$invoiceTotalAmount-$payPrice;
- return array('invoiceTotalAmount'=>sprintf ( "%.2f",$invoiceTotalAmount),
- 'payPrice'=>sprintf ( "%.2f",$payPrice),
- 'profit'=>sprintf ( "%.2f",$profit),
- 'unReceivablesTotalAmount'=>$unReceivablesTotalAmount,
- );
- }
- /**
- * @param string $sql
- */
- function initReceiptTrainRevenue($sql=""){
- Doo::loadModel ( 'invoice' );
- $invoice = new invoice ();
- $query = Doo::db ()->query ( $sql );
- $result = $query->fetchAll ();
- foreach ($result as $key=>$value){
- $invoiceList = $invoice->sumOfinvoiceTrain ( $value['invoiceTrainId'] );//开票合计-开票收入
- $invoiceRecelvablesList = $invoice->sumOfInvoiceRecelvablesTrain ( $value['invoiceTrainId'] );//入账合计-实际收入
- $invoiceTotalAmount=0;//开票金额合计
- $receivablesTotalAmount=0;//入账金额合计
- foreach ( $invoiceList as $k => $v ) {
- $invoiceTotalAmount+=$v ['invoicePrice'];
- }
- foreach ( $invoiceRecelvablesList as $i => $o ) {
- $receivablesTotalAmount+=$o ['receivablesPrice'];
- }
- //echo $invoiceTotalAmount.'-'.$receivablesTotalAmount.'</br>';
- if ($invoiceTotalAmount<=$receivablesTotalAmount){
- $itemData = array (
- 'rid' => $value['rid'],
- 'paidStatus' => 1,
- );
- $this->setReceiptByCondition($itemData);
- }
- }
- }
- /**
- * 获得培训班 年营收图表
- */
- function getReceiptTrainByYearChart($cid='',$year=''){
- if (empty($cid)){
- return array();
- }
- if(empty($year)){
- $year=date("Y");
- }
- $sql = "select GROUP_CONCAT(rid) as rid,GROUP_CONCAT(invoiceTrainId) as invoiceTrainId,date_format(date,\"%m\") as month
- from " . $this->_table . "
- where status not in (3,4,5) and Rtype=3 and trainId!=0 and invoiceTrainId!=0 and cid in (".$cid.") and paidStatus=1 and Year(date) =".$year."
- GROUP BY Month(date)";
- //
- $query = Doo::db ()->query ( $sql );
- $result = $query->fetchAll ();
- Doo::loadModel ( 'RItem' );
- $RItem = new RItem ();
- Doo::loadModel ( 'RILecturer' );
- $RILecturer = new RILecturer ();
- Doo::loadModel ( 'invoice' );
- $invoice = new invoice ();
- $MonthPriceList=array();
- foreach ($result as $key=>$value){
- //获得支出金额总和
- $RItemPrice=$RItem->getRItemPriceByRids($value['rid']);
- $RILecturerPrice=$RILecturer->getRILecturerPriceByRids($value['rid']);
- $RIprice=$RItemPrice+$RILecturerPrice;//支出金额合计
-
- //收款金额总和
- $ITprice=$invoice->getInvoicePriceByIids($value['invoiceTrainId']);
- $MonthPriceList[$value['month']]=array(
- 'RIprice'=>$RIprice,
- 'ITprice'=>$ITprice
- );
- }
- return $MonthPriceList;
- }
- function receiptByYear($dateCondition, $sid) {
- $sql = "select sum(sum) as sum from " . $this->_table . " where staff= '" . $sid . "' " . $dateCondition . " and status=2 ";
- // echo '<div style="display:none">'.$sql.'</div>';
- $query = Doo::db ()->query ( $sql );
- $result = $query->fetch ();
-
- return $result;
- }
- function getReceiptBySid($sid = '', $year = '', $month = '') {
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
-
- if (empty ( $sid ))
- return array ();
- $sql = 'select a.*
- from ' . $this->_table . ' as a left join CLD_receiptDetail as b on b.rid=a.rid
- where b.staff =' . $sid . ' and Month(b.pastDate)=' . $month . ' and Year(b.pastDate)=' . $year . ' and b.status=1
- GROUP BY b.rid';
-
- $query = Doo::db ()->query ( $sql );
- $list = $query->fetchAll ();
-
- foreach ( $list as $key => $value ) {
- $list [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
- }
- return $list;
- }
- function getReceiptByRid($rid = '') {
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
-
- Doo::loadModel ( 'L_category' );
- $Lcategory = new L_category ();
- Doo::loadModel ( 'staff' );
- $staff = new staff ();
-
- if (! is_numeric ( $rid ))
- $rid = $XDeode->decode ( $rid );
-
- $rinfo = $this->getOne ( array (
- 'where' => 'rid=' . $rid,
- 'asArray' => true
- ) );
-
- $rinfo ['ridKey'] = $XDeode->encode ( $rinfo ['rid'] );
- //$rinfo ['trainLoanRidKey'] = $XDeode->encode ( $rinfo ['trainLoanRid'] );
- $XDeode = new XDeode ( 7 );
- $rinfo ['ridKey7'] = $XDeode->encode ( $rinfo ['rid'] );
-
- $rinfo ['category'] = $Lcategory->getCategoryById ( $rinfo ['cid'] );
- $rinfo ['staffDetail'] = $staff->getStaffBySid ( $rinfo ['staff'] );
-
- // $rinfo['sum']=number_format ($rinfo['sum'],2);
-
- return $rinfo;
- }
-
- function getReceiptInRid($rid = ''){
-
- /*
- if (! is_numeric ( $rid )){
- $rid = $XDeode->decode ( $rid );
- } */
-
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- Doo::loadModel ( 'L_category' );
- $Lcategory = new L_category ();
- Doo::loadModel ( 'staff' );
- $staff = new staff ();
-
- $rinfo = $this->find ( array (
- 'where' => 'rid in (' . $rid.')',
- 'asArray' => true
- ) );
-
- foreach ($rinfo as $key=>$value){
- $rinfo [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
- //$rinfo [$key]['trainLoanRidKey'] = $XDeode->encode ( $value ['trainLoanRid'] );
- $XDeode = new XDeode ( 7 );
- $rinfo [$key]['ridKey7'] = $XDeode->encode ( $value ['rid'] );
-
- $rinfo[$key] ['category'] = $Lcategory->getCategoryById ( $value ['cid'] );
- $rinfo[$key] ['staffDetail'] = $staff->getStaffBySid ( $value ['staff'] );
- }
- //print_r($rinfo);
- return $rinfo;
- }
-
- function getReceiptByTrainLoanRid($rid = '') {
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
-
- // Doo::loadModel ( 'L_category' );
- // $Lcategory = new L_category ();
- // Doo::loadModel ( 'staff' );
- // $staff = new staff ();
-
- if (! is_numeric ( $rid )){
- $rid = $XDeode->decode ( $rid );
- }
- $rinfo = $this->getOne ( array (
- 'where' => 'trainLoanRid=' . $rid,
- 'asArray' => true
- ) );
-
- if(empty($rinfo)){
- $rinfo = $this->getOne ( array (
- 'where' => 'trainLoanRid like "' . $rid.',%"',
- 'asArray' => true
- ) );
- }
- if(empty($rinfo)){
- $rinfo = $this->getOne ( array (
- 'where' => 'trainLoanRid like "%,' . $rid.'"',
- 'asArray' => true
- ) );
- }
- if(empty($rinfo)){
- $rinfo = $this->getOne ( array (
- 'where' => 'trainLoanRid like "%,' . $rid.',%"',
- 'asArray' => true
- ) );
- }
-
- $rinfo ['ridKey7']='';
- if (!empty($rinfo ['rid'])){
- $XDeode = new XDeode ( 7 );
- $rinfo ['ridKey7'] = $XDeode->encode ( $rinfo ['rid'] );
- }
-
-
- // $rinfo ['ridKey7'] = $XDeode->encode ( $rinfo ['rid'] );
-
- // $rinfo ['category'] = $Lcategory->getCategoryById ( $rinfo ['cid'] );
- // $rinfo ['staffDetail'] = $staff->getStaffBySid ( $rinfo ['staff'] );
- // $rinfo['sum']=number_format ($rinfo['sum'],2);
-
- return $rinfo;
- }
-
- function getReceiptByinvoiceTrainId($invoiceTrainId = 0) {
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
-
- Doo::loadModel ( 'L_category' );
- $Lcategory = new L_category ();
- Doo::loadModel ( 'staff' );
- $staff = new staff ();
-
- if (! is_numeric ( $invoiceTrainId ))
- $invoiceTrainId = $XDeode->decode ( $invoiceTrainId );
-
- $rinfo = $this->getOne ( array (
- 'where' => 'invoiceTrainId=' . $invoiceTrainId,
- 'asArray' => true
- ) );
-
- if (empty ( $rinfo )) {
- return array ();
- }
-
- $rinfo ['ridKey'] = $XDeode->encode ( $rinfo ['rid'] );
- $rinfo ['trainLoanRidKey'] = '';//$XDeode->encode ( $rinfo ['trainLoanRid'] );
- $XDeode = new XDeode ( 7 );
- $rinfo ['ridKey7'] = $XDeode->encode ( $rinfo ['rid'] );
-
- $rinfo ['category'] = $Lcategory->getCategoryById ( $rinfo ['cid'] );
- $rinfo ['staffDetail'] = $staff->getStaffBySid ( $rinfo ['staff'] );
-
- return $rinfo;
- }
-
- /**
- * 默认获得10条
- * @param unknown $sid
- * @param unknown $cid
- * @param unknown $limit
- */
- function getReceiptLoanByStatus($sid, $cid, $status, $limit = 10) {
- $sql = '';
- if ($sid !== false && is_numeric ( $sid )) {
- $sql .= ' and staff=' . $sid;
- }
- if ($cid !== false && is_numeric ( $cid )) {
- $sql .= ' and cid=' . $cid;
- }
-
- $list = $this->find ( array (
- 'where' => 'Rtype=1 and status=' . $status . $sql,
- 'asArray' => true
- ) );
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- foreach ( $list as $key => $value ) {
- $list [$key] ['ridKey'] = $XDeode->encode ( $list [$key] ['rid'] );
- }
- return $list;
- }
-
- /**
- * 获得需要记录流水的费用
- * @param unknown $status
- * @return string
- */
- function getReceiptByWaste() {
- $list = $this->find ( array (
- 'where' => 'status=2 or status=6 or status=1',
- 'asArray' => true
- ) );
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- $XDeode7 = new XDeode ( 7 );
- Doo::loadModel ( 'wasteBook' );
- $wasteBook = new wasteBook ();
-
- $accountType = 0;
- foreach ( $list as $key => $value ) {
- $list [$key] ['ridKey7'] = $XDeode7->encode ( $list [$key] ['rid'] );
- $list [$key] ['ridKey'] = $XDeode->encode ( $list [$key] ['rid'] );
-
- if ($list [$key] ['Rtype'] == 0) {
- $accountType = 3;
- } elseif ($list [$key] ['Rtype'] == 1) {
- if (! empty ( $list [$key] ['accountItem'] ))
- $accountType = 2;
- else
- $accountType = 1;
- } elseif ($list [$key] ['Rtype'] == 2) {
- $accountType = 4;
- } elseif ($list [$key] ['Rtype'] == 3) {
- $accountType = 12;
- }
-
- // 是否已经生成流水
- $wbDetail = array ();
- if (! empty ( $accountType )) {
- $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $list [$key] ['rid'] );
- if (! empty ( $wbDetail )) {
- unset ( $list [$key] );
- }
- } else {
- unset ( $list [$key] );
- }
- }
- return $list;
- }
-
- /**
- * 根据参数字段更新相应字段(主键ID必须传)
- * @param array $item 相关需要更新的字段信息
- * @return number 返回发票ID
- */
- public function setReceiptByCondition($item = array(), $rid = "") {
- $lid = 0;
-
- if (is_array ( $item ) && ! empty ( $item )) {
- foreach ( $item as $key => $value ) {
- $this->$key = $value;
- }
-
- if (! empty ( $isid )) {
- $condition = array (
- 'where' => "rid in (" . $rid . ")",
- 'asArray' => TRUE
- );
- $this->update ( $condition );
- } else
- $lid = $this->update ();
- }
- return $lid;
- }
- }
- ?>
|