예제 #1
0
 public function GetOperationsByClientId(Gyuser_Model_Operations $obj)
 {
     $table = $this->getDbTable();
     $select = $table->select();
     $select->setIntegrityCheck(false);
     $select->from(array('ope' => 'operations'), array('id', 'type', 'state_order_id', 'amount', 'tasa_porcentual', 'date', 'ac_date', 'state_change', 'cave_id', 'report'));
     $select->joinLeft(array('ope_s' => 'operations_state'), 'ope.state_order_id = ope_s.id', array('name as state_name', 'order_id'));
     //$select->joinLeft(array('ocvs' => 'other_caves'), 'ope.cave_id = ocvs.id', array('name as cave_name'));
     $select->joinLeft(array('provs' => 'providers'), 'ope.cave_id = provs.id', array('name as prov_name'));
     $select->where('ope.client_id = ?', $obj->getClient_id());
     $select->order('ope.id DESC');
     $resultSet = $table->fetchAll($select);
     if ($resultSet) {
         $entries = array();
         $mapper = new Gyuser_Model_ChequesDataMapper();
         foreach ($resultSet as $row) {
             $operationid = $row->id;
             $stateChange = date("d/m H:i", strtotime($row->state_change)) . ' hs';
             if ($row->state_order_id == 99) {
                 $stateChange = date("d/m/Y", strtotime($row->state_change));
             }
             $entry = array('stateid' => $row->state_order_id, 'type' => $row->type, 'state_name' => $row->state_name, 'operationid' => $operationid, 'amount' => $row->amount, 'tasa' => $row->tasa_porcentual, 'date' => date("d/m/Y", strtotime($row->date)), 'ac_date' => date("d/m/Y", strtotime($row->ac_date)), 'state_change' => $stateChange, 'cave_id' => $row->cave_id, 'cave_name' => $row->prov_name, 'report' => $row->report);
             $cheques = $mapper->GetChequeDetailsByOpId($operationid);
             $entry['cheques'] = $cheques;
             $entries[$operationid] = $entry;
         }
         return $entries;
     } else {
         return null;
     }
 }