PageRenderTime 43ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/application/models/advertises_model.php

https://code.google.com/p/travelcrm/
PHP | 11 lines | 10 code | 1 blank | 0 comment | 9 complexity | 6f06307bafe9a39c2df6e7ade8512d99 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php include_once APPPATH."libraries/core/Docmodel.php"; class Advertises_model extends Docmodel{ public function __construct(){ parent::__construct(); }
  2. public function get_ds(){ $this->db->select('SQL_CALC_FOUND_ROWS _documents.rid, DATE_FORMAT(_advertises_headers.date_doc, \'%d.%m.%Y\') as date_doc, DATE_FORMAT(_advertises_headers.bdate, \'%d.%m.%Y\') as bdate, DATE_FORMAT(_advertises_headers.edate, \'%d.%m.%Y\') as edate, _advertises_headers.sum as sum, _advertisescompanies.company_name as company_name, _advertisessources.source_name as source_name, DATE_FORMAT(_documents.modifyDT, \'%d.%m.%Y\') as modifyDT, _documents.descr as descr, _documents.archive', False); $this->db->from('_documents'); $this->db->join('_advertises_headers', '_advertises_headers._documents_rid = _documents.rid'); $this->db->join('_advertises_rows', '_advertises_rows._advertises_headers_rid = _advertises_headers.rid'); $this->db->join('_advertisessources', '_advertises_headers._advertisessources_rid = _advertisessources.rid', 'LEFT'); $this->db->join('_advertisescompanies', '_advertises_headers._advertisescompanies_rid = _advertisescompanies.rid', 'LEFT'); $this->db->group_by('_documents.rid'); $this->db->where(array('_documents.doc_type'=>$this->ci->get_typedoc())); if($searchRule = element('like', $this->ci->get_session('searchrule'), null)) $this->db->like($searchRule); if($searchRule = element('where', $this->ci->get_session('searchrule'), null)) $this->db->where($searchRule); if($sort = $this->ci->get_session('sort')) $this->db->orderby($sort['c'], $sort['r']); $this->db->limit($this->ci->config->item('crm_grid_limit'), element('p', $this->ci->a_uri_assoc, null)); $query = $this->db_get('_documents'); return $query->num_rows()?$query->result():array(); }
  3. public function get_edit($rid){ $this->db->select('_documents.rid, _documents.owner_users_rid, _advertises_headers._advertisescompanies_rid, _advertises_headers._advertisessources_rid, _advertises_headers._currencies_rid, _advertises_headers.sum, DATE_FORMAT(_advertises_headers.date_doc, \'%d.%m.%Y\') as date_doc, DATE_FORMAT(_advertises_headers.bdate, \'%d.%m.%Y\') as bdate, DATE_FORMAT(_advertises_headers.edate, \'%d.%m.%Y\') as edate, DATE_FORMAT(_documents.modifyDT, \'%d.%m.%Y %H:%i\') as modifyDT, _documents.descr as descr, _documents.archive', False); $this->db->from('_documents'); $this->db->join('_advertises_headers', '_advertises_headers._documents_rid = _documents.rid'); $this->db->where(array('_documents.rid'=>$rid)); $query = $this->db_get('_documents'); return $query->num_rows()?$query->row():False; }
  4. public function create_record(){ $ins_doc = array('doc_type'=>$this->ci->get_typedoc(), 'descr'=>$this->ci->input->post('descr'), 'archive'=>$this->ci->input->post('archive'), 'owner_users_rid'=>get_curr_urid(), 'modifier_users_rid'=>get_curr_urid()); $this->db->set('createDT', 'now()', False); $this->db->set('modifyDT', 'now()', False); $this->db->trans_begin(); $this->db->insert('_documents', $ins_doc); $doc_rid = $this->db->insert_id(); $sums = $this->input->post('row_sum')?$this->input->post('row_sum'):array(); $sum = 0; foreach($sums as $s) $sum += $s; $ins_h = array('date_doc'=>date('Y-m-d', strtotime($this->ci->input->post('date_doc'))), '_documents_rid'=>$doc_rid, '_advertisescompanies_rid'=>$this->ci->input->post('_advertisescompanies_rid'), '_advertisessources_rid'=>$this->ci->input->post('_advertisessources_rid'), '_currencies_rid'=>$this->ci->input->post('_currencies_rid'), 'bdate'=>date('Y-m-d', strtotime($this->ci->input->post('bdate'))), 'edate'=>date('Y-m-d', strtotime($this->ci->input->post('edate'))), 'sum'=>floatval($sum), 'owner_users_rid'=>get_curr_urid(), 'modifier_users_rid'=>get_curr_urid()); $this->db->set('createDT', 'now()', False); $this->db->set('modifyDT', 'now()', False); $this->db->insert('_advertises_headers', $ins_h); $header_rid = $this->db->insert_id(); $filials = $this->input->post('f_rid')?$this->input->post('f_rid'):array(); foreach($filials as $key=>$f){ $ins_r = array('_advertises_headers_rid'=>$header_rid, '_filials_rid'=>$f, 'sum'=>floatval($sums[$key]), 'owner_users_rid'=>get_curr_urid(), 'modifier_users_rid'=>get_curr_urid()); $this->db->set('createDT', 'now()', False); $this->db->set('modifyDT', 'now()', False); $this->db->insert('_advertises_rows', $ins_r); } if ($this->db->trans_status() === FALSE){ $this->db->trans_rollback(); return False; }else{ $this->db->trans_commit(); return $doc_rid; } }
  5. public function get_rows($rid){ $this->db->select('_advertises_rows._filials_rid as filial, _advertises_rows.sum as sum'); $this->db->from('_advertises_rows'); $this->db->join('_advertises_headers', '_advertises_headers.rid = _advertises_rows._advertises_headers_rid'); $this->db->where(array('_advertises_headers._documents_rid'=>$rid)); $query = $this->db_get('_documents'); return $query->num_rows()?$query->result_array():array(); } public function get_all_filials(){ $query = $this->db->select("_filials.rid as filial")->from('_filials')->order_by('_filials.name')->get(); return $query->num_rows()?$query->result_array():array(); }
  6. public function update_record(){
  7. $update_doc = array('doc_type'=>$this->ci->get_typedoc(), 'descr'=>$this->ci->input->post('descr'), 'archive'=>$this->ci->input->post('archive'), 'modifier_users_rid'=>get_curr_urid()); $this->db->set('modifyDT', 'now()', False); $this->db->trans_begin(); $this->db->update('_documents', $update_doc, array('_documents.rid'=>$this->ci->input->post('rid'))); $sums = $this->input->post('row_sum')?$this->input->post('row_sum'):array(); $sum = 0; foreach($sums as $s) $sum += $s; $update_h = array('date_doc'=>date('Y-m-d', strtotime($this->ci->input->post('date_doc'))), '_advertisescompanies_rid'=>$this->ci->input->post('_advertisescompanies_rid'), '_advertisessources_rid'=>$this->ci->input->post('_advertisessources_rid'), '_currencies_rid'=>$this->ci->input->post('_currencies_rid'), 'bdate'=>date('Y-m-d', strtotime($this->ci->input->post('bdate'))), 'edate'=>date('Y-m-d', strtotime($this->ci->input->post('edate'))), 'sum'=>floatval($sum), 'modifier_users_rid'=>get_curr_urid()); $this->db->set('modifyDT', 'now()', False); $this->db->update('_advertises_headers', $update_h, array('_advertises_headers._documents_rid'=>$this->ci->input->post('rid'))); $query = $this->db->getwhere('_advertises_headers', array('_advertises_headers._documents_rid'=>$this->ci->input->post('rid'))); if(!$query->num_rows()) { $this->db->trans_rollback(); return False; } $row = $query->row(); $filials = $this->input->post('f_rid')?$this->input->post('f_rid'):array(); $this->db->delete('_advertises_rows', array('_advertises_headers_rid'=>$row->rid)); foreach($filials as $key=>$f){ $ins_r = array('_advertises_headers_rid'=>$row->rid, '_filials_rid'=>$f, 'sum'=>floatval($sums[$key]), 'owner_users_rid'=>get_curr_urid(), 'modifier_users_rid'=>get_curr_urid()); $this->db->set('createDT', 'now()', False); $this->db->set('modifyDT', 'now()', False); $this->db->insert('_advertises_rows', $ins_r); } if ($this->db->trans_status() === FALSE){ $this->db->trans_rollback(); return False; }else{ $this->db->trans_commit(); return $this->ci->input->post('rid'); } }
  8. public function get_attaches($doc_rid){ $this->db->select('_attaches.*, _documents_attaches.rid as dattach_rid'); $this->db->from('_attaches'); $this->db->join('_documents_attaches', '_documents_attaches._attaches_rid = _attaches.rid'); $this->db->where(array('_documents_attaches._documents_rid'=>$doc_rid)); $this->db->order_by('_attaches.rid'); $query = $this->db->get(); return $query->num_rows()?$query->result():array(); } public function addattach(){ $this->db->trans_begin(); $upload_data = $this->ci->upload->data(); $ins_r = array('file_descr'=>$this->ci->input->post('upload_descr')?$this->ci->input->post('upload_descr'):$upload_data['file_name'], 'file_name'=>$upload_data['file_name'], 'file_type'=>$upload_data['file_type'], 'file_size'=>$upload_data['file_size'], 'file_path'=>$upload_data['file_path']); $this->db->insert('_attaches', $ins_r); $attach_rid = $this->db->insert_id(); $ins_r = array('_documents_rid'=>$this->ci->input->post('_documents_rid'), '_attaches_rid'=>$attach_rid); $this->db->insert('_documents_attaches', $ins_r); if ($this->db->trans_status() === FALSE){ $this->db->trans_rollback(); return False; }else{ $this->db->trans_commit(); return True; } } public function removeattach($rid){ $this->db->trans_begin(); $query = $this->db->select('*')->from('_attaches')->where(array('rid'=>$rid))->get(); if($query->num_rows()){ $row = $query->row(); @unlink($row->file_path.$row->file_name); } $this->db->delete('_attaches', array('rid'=>$rid)); if ($this->db->trans_status() === FALSE){ $this->db->trans_rollback(); return False; }else{ $this->db->trans_commit(); return True; } }
  9. }
  10. ?>