Пример #1
0
 public function journal($agent, $agent_id, $voucher_ids, $sort, $where = '')
 {
     include_once APPPATH . "models/helperClasses/Universal_Voucher.php";
     include_once APPPATH . "models/helperClasses/Voucher_Entry.php";
     $this->db->select("voucher_journal.id as voucher_id, voucher_journal.ignored, voucher_entry.id as voucher_entry_id,\r                            voucher_journal.voucher_date, voucher_journal.detail, voucher_journal.person_tid,\r                            voucher_journal.trip_id,voucher_journal.trip_product_detail_id, voucher_journal.tanker_id, tankers.truck_number as tanker_number,\r                            voucher_journal.entryDate,\r                            voucher_entry.id as voucher_entry_id, voucher_entry.related_other_agent,\r                             voucher_entry.related_customer, voucher_entry.related_contractor,\r                            voucher_entry.description, account_titles.title, account_titles.id as account_title_id,\r                             account_titles.type as ac_type, voucher_entry.debit_amount,\r                            voucher_entry.credit_amount, voucher_entry.dr_cr,\r                            companies.name as company_name, voucher_entry.related_company,\r                            other_agents.name as related_other_agent_name, customers.name as related_customer_name, carriage_contractors.name as related_contractor_name, companies.name as related_company_name,\r        ");
     $this->db->from('voucher_journal');
     $this->db->join('voucher_entry', 'voucher_entry.journal_voucher_id = voucher_journal.id', 'left');
     $this->db->join('other_agents', 'other_agents.id = voucher_entry.related_other_agent', 'left');
     $this->db->join('customers', 'customers.id = voucher_entry.related_customer', 'left');
     $this->db->join('carriage_contractors', 'carriage_contractors.id = voucher_entry.related_contractor', 'left');
     $this->db->join('companies', 'companies.id = voucher_entry.related_company', 'left');
     $this->db->join('account_titles', 'account_titles.id = voucher_entry.account_title_id', 'left');
     $this->db->join('tankers', 'tankers.id = voucher_journal.tanker_id', 'left');
     if ($voucher_ids != "") {
         $this->db->where_in('voucher_journal.id', $voucher_ids);
     }
     //sorting
     if ($sort != '') {
         $this->db->order_by('voucher_journal.id', $sort['order']);
     } else {
         $this->db->order_by('voucher_journal.id', 'asc');
     }
     $this->db->order_by('voucher_entry.dr_cr', 'asc');
     $result = $this->db->get()->result();
     $previous_voucher_id = -1;
     $temp_voucher = new Universal_Voucher();
     $final_journal = array();
     $count = 0;
     foreach ($result as $voucher) {
         $count++;
         if ($voucher->voucher_id != $previous_voucher_id) {
             if ($previous_voucher_id != -1) {
                 array_push($final_journal, $temp_voucher);
             }
             $previous_voucher_id = $voucher->voucher_id;
             $temp_voucher = new Universal_Voucher();
             //setting data in the parent object
             $temp_voucher->voucher_id = $voucher->voucher_id;
             $temp_voucher->ignore = $voucher->ignored;
             $temp_voucher->voucher_details = $voucher->detail;
             $temp_voucher->voucher_date = $voucher->voucher_date;
             $temp_voucher->tanker_id = $voucher->tanker_id;
             $temp_voucher->tanker_number = $voucher->tanker_number;
             $temp_voucher->trip_id = $voucher->trip_id;
             $temp_voucher->trip_detail_id = $voucher->trip_product_detail_id;
             $person = explode('.', $voucher->person_tid);
             $temp_voucher->person_id = $person[1];
             $temp_voucher->person = $person[0];
         }
         //making a voucher Entry
         $temp_voucher_entry = new Voucher_Entry();
         //setting data in temp_voucher_entry
         $temp_voucher_entry->setId($voucher->voucher_entry_id);
         $temp_voucher_entry->setAc_type($voucher->ac_type);
         $temp_voucher_entry->setTitle($voucher->title);
         $temp_voucher_entry->setAccount_title_id($voucher->account_title_id);
         $temp_voucher_entry->setDescription($voucher->description);
         //finding the related agent
         $related_agent = '';
         $related_agent_id = '';
         $related_agent_name = '';
         if ($voucher->related_other_agent != 0) {
             $related_agent = "other_agents";
             $related_agent_id = $voucher->related_other_agent;
             $related_agent_name = $voucher->related_other_agent_name;
         } else {
             if ($voucher->related_customer != 0) {
                 $related_agent = "customers";
                 $related_agent_id = $voucher->related_customer;
                 $related_agent_name = $voucher->related_customer_name;
             } else {
                 if ($voucher->related_contractor != 0) {
                     $related_agent = "carriage_contractors";
                     $related_agent_id = $voucher->related_contractor;
                     $related_agent_name = $voucher->related_contractor_name;
                 } else {
                     if ($voucher->related_company != 0) {
                         $related_agent = "companies";
                         $related_agent_id = $voucher->related_company;
                         $related_agent_name = $voucher->related_company_name;
                     } else {
                         $related_agent = "self";
                         $related_agent_id = 0;
                         $related_agent_name = '';
                     }
                 }
             }
         }
         $temp_voucher_entry->setRelated_agent($related_agent);
         $temp_voucher_entry->setRelated_agent_id($related_agent_id);
         $temp_voucher_entry->setRelated_agent_name($related_agent_name);
         $temp_voucher_entry->setDebit($voucher->debit_amount);
         $temp_voucher_entry->setCredit($voucher->credit_amount);
         $dr_cr = $voucher->dr_cr == 0 ? 'credit' : 'debit';
         $temp_voucher_entry->setDr_cr($dr_cr);
         $temp_voucher_entry->setJournal_voucher_id($voucher->voucher_id);
         //insert voucher entry into the voucher
         array_unshift($temp_voucher->entries, $temp_voucher_entry);
         //checking if the record is final
         if ($count == sizeof($result)) {
             array_push($final_journal, $temp_voucher);
         }
     }
     return $final_journal;
 }
Пример #2
0
 public function customer_credit_voucher($trip_id, $trip_detail_id, $total_creditable_amount, $credit_amount, $agent_type, $agent_id, $voucher_date, $other_info)
 {
     include_once APPPATH . "models/helperClasses/Universal_Voucher.php";
     include_once APPPATH . "models/helperClasses/Voucher_Entry.php";
     $voucher = new Universal_Voucher();
     //fetching the tanker id
     $this->db->select('tanker_id, customer_id');
     $result = $this->db->get_where('trips', array('id' => $trip_id))->result();
     if ($result != null) {
         $tanker_id = $result[0]->tanker_id;
         $customer_id = $result[0]->customer_id;
     } else {
         $tanker_id = 0;
         $customer_id = 0;
     }
     //setting voucher data
     $voucher->trip_id = $trip_id == 'none' ? '' : $trip_id;
     $voucher->voucher_date = $voucher_date == 'none' ? '' : $voucher_date;
     $voucher->voucher_details = $other_info == 'none' ? '' : str_replace("%20", " ", $other_info);
     $voucher->tanker_id = $tanker_id;
     $voucher->person_id = $customer_id;
     $voucher->trip_detail_id = $trip_detail_id;
     /////Setting the entries.....
     $voucher_entry = new Voucher_Entry();
     $description = "";
     $this->db->select('id');
     $result = $this->db->get_where('account_titles', array('title' => 'freight'))->result();
     $account_title_id = sizeof($result) >= 1 ? $result[0]->id : 0;
     $amount_1 = $credit_amount;
     //set all properties here and then
     $voucher_entry->setAc_type('dividend');
     $voucher_entry->setAccount_title_id($account_title_id);
     $voucher_entry->setDescription($description);
     $voucher_entry->setRelated_agent('self');
     $voucher_entry->setDebit($amount_1);
     $voucher_entry->setDr_cr('debit');
     array_push($voucher->entries, $voucher_entry);
     $voucher_entry = new Voucher_Entry();
     //set all properties here and then
     $agent_id_2 = $agent_id == 'none' ? '' : $agent_id;
     $related_agent = $agent_type == 'none' ? 'self' : $agent_type;
     $amount_2 = $credit_amount;
     $ac_type = 'payable';
     $voucher_entry->setAc_type($ac_type);
     $voucher_entry->setAccount_title_id($account_title_id);
     $voucher_entry->setDescription($description);
     $voucher_entry->setRelated_agent($related_agent);
     $voucher_entry->setRelated_agent_id($agent_id_2);
     $voucher_entry->setCredit($amount_2);
     $voucher_entry->setDr_cr('credit');
     array_push($voucher->entries, $voucher_entry);
     ////////////////////////////////////////
     $bodyData['voucher'] = $voucher;
     //finding the max trip id
     $this->db->select_max('id');
     $result = $this->db->get('trips')->result();
     $bodyData['max_trip_id'] = $result[0]->id;
     ////////////////////////////////////////
     $bodyData['trip_detail_id'] = $trip_detail_id;
     $bodyData['total_creditable_amount'] = $total_creditable_amount;
     $bodyData['account_holders'] = $this->carriageContractors_model->carriageContractors();
     $bodyData['tankers'] = $this->tankers_model->tankers();
     $bodyData['other_agents'] = $this->otherAgents_model->otherAgents();
     $bodyData['titles'] = $this->accounts_model->account_titles();
     $this->load->view('accounts/components/vouchers/customer_credit_voucher', $bodyData);
 }