Exemplo n.º 1
0
 public function parametrized_trips_engine_for_manageaccounts($trip_detail_ids, $aimed_for)
 {
     include_once APPPATH . "models/helperClasses/Trip.php";
     include_once APPPATH . "models/helperClasses/Trip_Product_Detail.php";
     include_once APPPATH . "models/helperClasses/Customer.php";
     include_once APPPATH . "models/helperClasses/Contractor.php";
     include_once APPPATH . "models/helperClasses/Company.php";
     include_once APPPATH . "models/helperClasses/Driver.php";
     include_once APPPATH . "models/helperClasses/Tanker.php";
     include_once APPPATH . "models/helperClasses/City.php";
     include_once APPPATH . "models/helperClasses/Product.php";
     include_once APPPATH . "models/helperClasses/Voucher_Entry.php";
     include_once APPPATH . "models/helperClasses/Bill.php";
     /*
      * -----------------------------
      *  Fetching trips_details ids
      * ----------------------------
      *  The reason is that we want
      *  to use these ids in
      *  where_in query for join
      *  trips table to the journal
      *  tables..
      * --------------------------*/
     /*$this->db->select('id');
       $this->db->where_in('trips_details.trip_id',$trips_ids);
       $result = $this->db->get('trips_details')->result();
       $detail_ids = array();
       foreach($result as $r)
       {
           array_push($detail_ids, $r->id);
       }*/
     /**********************************/
     ////**********************selecte statement starts*********************/////
     $select = "trips.id as trip_id,\n         trips.customer_id, customers.name as customerName,\n          trips.contractor_id, carriage_contractors.name as contractorName,\n           trips.company_id, companies.name as companyName, trips.tanker_id,\n            tankers.truck_number as tanker_number, tankers.capacity, trips.contractor_commission,\n            trips.contractor_commission_1, trips.contractor_commission_2,\n             trips.company_commission_1, trips.company_commission_2 as wht, trips.company_commission_3,\n             trips.type as trip_type,\n              trips.driver_id_1, drivers_1.name as driver_1_name, trips.driver_id_2,\n               drivers_2.name as driver_2_name, trips.driver_id_3,\n                drivers_3.name as driver_3_name, trips.filling_date, trips.decanding_date,\n                 trips.email_date, trips.stn_receiving_date, trips.receiving_date,\n                  trips.invoice_date, trips.invoice_number, trips.entryDate,\n                   trips_details.id as trips_details_id, trips_details.product_quantity,\n                    trips_details.qty_at_destination, trips_details.qty_after_decanding,\n                     trips_details.price_unit, freight_unit, trips_details.stn_number, trips_details.shortage_voucher_dest,\n                     trips_details.shortage_voucher_decnd, trips_details.source as source_id,\n                      trips_details.destination as destination_id, trips_details.product,\n                      source_cities.cityName as sourceCityName, trips_details.source as sourceCityId,\n                      destination_cities.cityName as destinationCityName, trips_details.destination as destinationCityId,\n                      products.productName,products.type as product_type, trips_details.product as productId, trips_details.company_freight_unit,\n                      trips_details.bill_id, bills.billed_date_time,\n                      ";
     //applying the where condition...
     if (sizeof($trip_detail_ids) >= 1) {
         $this->db->where_in('trips_details.id', $trip_detail_ids);
     } else {
         $this->db->where('trips_details.id', 0);
     }
     ////////////////////////////////////
     $this->db->from('trips_details');
     $this->db->where('trips.active', 1);
     //join starts..
     $this->db->join('trips', 'trips.id = trips_details.trip_id', 'left');
     $this->db->join('bills', 'bills.id = trips_details.id', 'left');
     //joining customers, contractors and companies
     $this->db->join('customers', 'customers.id = trips.customer_id', 'left');
     $this->db->join('carriage_contractors', 'carriage_contractors.id = trips.contractor_id', 'left');
     $this->db->join('companies', 'companies.id = trips.company_id', 'left');
     //joining tankers
     $this->db->join('tankers', 'tankers.id = trips.tanker_id', 'left');
     //joining drivers
     $this->db->join('drivers as drivers_1', 'drivers_1.id = trips.driver_id_1', 'left');
     $this->db->join('drivers as drivers_2', 'drivers_2.id = trips.driver_id_2', 'left');
     $this->db->join('drivers as drivers_3', 'drivers_3.id = trips.driver_id_3', 'left');
     //joining cites and routes etc..
     $this->db->join('cities as source_cities', 'source_cities.id = trips_details.source', 'left');
     $this->db->join('cities as destination_cities', 'destination_cities.id = trips_details.destination', 'left');
     $this->db->join('products', 'products.id = trips_details.product', 'left');
     //computing the required query aimed for
     switch ($aimed_for) {
         case "contractor_accounts":
             //select statement
             $select .= "\n                    voucher_journal_for_contractor_accounts.id as contractor_accounts_voucher_id,\n                    voucher_journal_for_contractor_accounts_entry.credit_amount as contractor_accounts_voucher_entry_credit_amount,\n                    voucher_journal_for_contractor_accounts_entry.related_other_agent as contractor_accounts_voucher_entry_related_other_agent,\n                    voucher_journal_for_contractor_accounts_entry.related_customer as contractor_accounts_voucher_entry_related_customer,\n                    voucher_journal_for_contractor_accounts_entry.related_contractor as contractor_accounts_voucher_entry_related_contractor,\n                    voucher_journal_for_contractor_accounts_entry.related_company as contractor_accounts_voucher_entry_related_company,\n                    voucher_journal_for_contractor_accounts.active as contractor_accounts_voucher_active,\n                    voucher_journal_for_contractor_accounts_entry.ac_type as contractor_accounts_voucher_entry_ac_type,\n                    voucher_journal_for_contractor_accounts_entry.id as contractor_accounts_voucher_entry_id,\n                    account_titles_for_contractor_accounts.title as contractor_accounts_title,\n                    voucher_journal_for_contractor_accounts_entry.account_title_id as contractor_accounts_title_id,\n                    voucher_journal_for_contractor_accounts.person_tid as contractor_accounts_voucher_person_tid,\n\n                ";
             //joins statements
             $this->db->join('voucher_journal as voucher_journal_for_contractor_accounts', 'voucher_journal_for_contractor_accounts.trip_product_detail_id = trips_details.id', 'left');
             $this->db->join('voucher_entry as voucher_journal_for_contractor_accounts_entry', 'voucher_journal_for_contractor_accounts_entry.journal_voucher_id = voucher_journal_for_contractor_accounts.id', 'left');
             $this->db->join('account_titles as account_titles_for_contractor_accounts', 'account_titles_for_contractor_accounts.id = voucher_journal_for_contractor_accounts_entry.account_title_id', 'left');
             break;
         case "customer_accounts":
             //select statement
             $select .= "\n                    voucher_journal_for_customer_accounts.id as customer_accounts_voucher_id,\n                    voucher_journal_for_customer_accounts_entry.credit_amount as customer_accounts_voucher_entry_credit_amount,\n                    voucher_journal_for_customer_accounts_entry.related_other_agent as customer_accounts_voucher_entry_related_other_agent,\n                    voucher_journal_for_customer_accounts_entry.related_customer as customer_accounts_voucher_entry_related_customer,\n                    voucher_journal_for_customer_accounts_entry.related_contractor as customer_accounts_voucher_entry_related_contractor,\n                    voucher_journal_for_customer_accounts_entry.related_company as customer_accounts_voucher_entry_related_company,\n                    voucher_journal_for_customer_accounts.active as customer_accounts_voucher_active,\n                    voucher_journal_for_customer_accounts_entry.ac_type as customer_accounts_voucher_entry_ac_type,\n                    voucher_journal_for_customer_accounts_entry.id as customer_accounts_voucher_entry_id,\n                    account_titles_for_customer_accounts.title as customer_accounts_title,\n                    voucher_journal_for_customer_accounts_entry.account_title_id as customer_accounts_title_id,\n                    voucher_journal_for_customer_accounts.person_tid as customer_accounts_voucher_person_tid,\n\n                ";
             //joins statements
             $this->db->join('voucher_journal as voucher_journal_for_customer_accounts', 'voucher_journal_for_customer_accounts.trip_product_detail_id = trips_details.id', 'left');
             $this->db->join('voucher_entry as voucher_journal_for_customer_accounts_entry', 'voucher_journal_for_customer_accounts_entry.journal_voucher_id = voucher_journal_for_customer_accounts.id', 'left');
             $this->db->join('account_titles as account_titles_for_customer_accounts', 'account_titles_for_customer_accounts.id = voucher_journal_for_customer_accounts_entry.account_title_id', 'left');
             break;
         case "company_accounts":
             //select statement
             $select .= "\n                    voucher_journal_for_company_accounts.id as company_accounts_voucher_id,\n                    voucher_journal_for_company_accounts_entry.credit_amount as company_accounts_voucher_entry_credit_amount,\n                    voucher_journal_for_company_accounts_entry.related_other_agent as company_accounts_voucher_entry_related_other_agent,\n                    voucher_journal_for_company_accounts_entry.related_customer as company_accounts_voucher_entry_related_customer,\n                    voucher_journal_for_company_accounts_entry.related_contractor as company_accounts_voucher_entry_related_contractor,\n                    voucher_journal_for_company_accounts_entry.related_company as company_accounts_voucher_entry_related_company,\n                    voucher_journal_for_company_accounts.active as company_accounts_voucher_active,\n                    voucher_journal_for_company_accounts_entry.ac_type as company_accounts_voucher_entry_ac_type,\n                    voucher_journal_for_company_accounts_entry.id as company_accounts_voucher_entry_id,\n                    account_titles_for_company_accounts.title as company_accounts_title,\n                    voucher_journal_for_company_accounts_entry.account_title_id as company_accounts_title_id,\n                    voucher_journal_for_company_accounts.person_tid as company_accounts_voucher_person_tid,\n\n                ";
             //joins statements
             $this->db->join('voucher_journal as voucher_journal_for_company_accounts', 'voucher_journal_for_company_accounts.trip_product_detail_id = trips_details.id', 'left');
             $this->db->join('voucher_entry as voucher_journal_for_company_accounts_entry', 'voucher_journal_for_company_accounts_entry.journal_voucher_id = voucher_journal_for_company_accounts.id', 'left');
             $this->db->join('account_titles as account_titles_for_company_accounts', 'account_titles_for_company_accounts.id = voucher_journal_for_company_accounts_entry.account_title_id', 'left');
             break;
         case "manage_accounts":
             //select statement
             $select .= "\n                    voucher_journal_for_manage_accounts.id as manage_accounts_voucher_id,\n                    voucher_journal_for_manage_accounts.voucher_date as manage_accounts_voucher_date,\n                    voucher_journal_for_manage_accounts_entry.credit_amount as manage_accounts_voucher_entry_credit_amount,\n                    voucher_journal_for_manage_accounts_entry.related_other_agent as manage_accounts_voucher_entry_related_other_agent,\n                    voucher_journal_for_manage_accounts_entry.related_customer as manage_accounts_voucher_entry_related_customer,\n                    voucher_journal_for_manage_accounts_entry.related_contractor as manage_accounts_voucher_entry_related_contractor,\n                    voucher_journal_for_manage_accounts_entry.related_company as manage_accounts_voucher_entry_related_company,\n                    voucher_journal_for_manage_accounts_entry.dr_cr as manage_accounts_voucher_entry_dr_cr,\n                    voucher_journal_for_manage_accounts.active as manage_accounts_voucher_active,\n                    account_titles_for_manage_accounts.type as manage_accounts_voucher_entry_ac_type,\n                    voucher_journal_for_manage_accounts_entry.id as manage_accounts_voucher_entry_id,\n                    trip_detail_voucher_relation_for_manage_accounts.id as trip_detail_voucher_relation_for_manage_accounts_id,\n                    account_titles_for_manage_accounts.title as manage_accounts_title,\n                    voucher_journal_for_manage_accounts_entry.account_title_id as manage_accounts_title_id,\n                    voucher_journal_for_manage_accounts.person_tid as manage_accounts_voucher_person_tid,\n\n                ";
             //joins statements
             $this->db->join('trip_detail_voucher_relation as trip_detail_voucher_relation_for_manage_accounts', 'trip_detail_voucher_relation_for_manage_accounts.trip_detail_id = trips_details.id', 'left');
             $this->db->join('voucher_journal as voucher_journal_for_manage_accounts', 'voucher_journal_for_manage_accounts.id = trip_detail_voucher_relation_for_manage_accounts.voucher_id', 'left');
             $this->db->join('voucher_entry as voucher_journal_for_manage_accounts_entry', 'voucher_journal_for_manage_accounts_entry.journal_voucher_id = voucher_journal_for_manage_accounts.id', 'left');
             $this->db->join('account_titles as account_titles_for_manage_accounts', 'account_titles_for_manage_accounts.id = voucher_journal_for_manage_accounts_entry.account_title_id', 'left');
             //where statements
             $this->db->where_in('trip_detail_voucher_relation_for_manage_accounts.trip_detail_id', $trip_detail_ids);
             $this->db->where(array('voucher_journal_for_manage_accounts.active' => 1));
             break;
         default:
             break;
     }
     ///////////////////////////////
     $this->db->select($select);
     //select ends...
     /*--**********************joining ends*********************--*/
     $this->db->order_by('trips.id, trips_details.id');
     $rawTrips = $this->db->get()->result();
     //die(var_dump($rawTrips));
     $final_trips_array = array();
     //arrays which will hold ids for record settings
     $contractor_account_ids = array();
     $company_account_ids = array();
     $customer_account_ids = array();
     $contractor_accounts_voucher_entry_ids = array();
     $customer_accounts_voucher_entry_ids = array();
     $company_accounts_voucher_entry_ids = array();
     $trip_detail_voucher_relation_for_manage_accounts_ids = array();
     ////////////////////////////////////////////////////
     $previous_trip_id = -1;
     $previous_trip_product_detail_id = -1;
     $previous_customer_account_id = -1;
     $previous_contractor_account_id = -1;
     $previous_company_account_id = -1;
     $temp_trip = new Trip();
     $temp_trip_product_detail = new Trip_Product_Detail($temp_trip);
     $temp_contractor_accounts_voucher_entry = new Voucher_Entry();
     $temp_customer_accounts_voucher_entry = new Voucher_Entry();
     $temp_company_accounts_voucher_entry = new Voucher_Entry();
     $temp_manage_accounts_voucher_entry = new Voucher_Entry();
     $count = 0;
     foreach ($rawTrips as $record) {
         $count++;
         //setting the parent details
         if ($record->trip_id != $previous_trip_id) {
             $previous_trip_id = $record->trip_id;
             //$previous_trip_obj = $temp_trip;
             $temp_trip = new trip();
             //setting data in the parent object
             $temp_trip->trip_id = $record->trip_id;
             $temp_trip->type = $record->trip_type;
             $temp_trip->customer = new Customer($record->customer_id, $record->customerName, 100 - $record->contractor_commission);
             $temp_trip->contractor = new Contractor($record->contractor_id, $record->contractorName, $record->contractor_commission);
             $temp_trip->company = new Company($record->company_id, $record->companyName, $record->company_commission_1, $record->wht);
             $temp_trip->driver_1 = new Driver($record->driver_id_1, $record->driver_1_name);
             $temp_trip->driver_2 = new Driver($record->driver_id_2, $record->driver_2_name);
             $temp_trip->driver_3 = new Driver($record->driver_id_3, $record->driver_3_name);
             $temp_trip->tanker = new Tanker($record->tanker_id, $record->tanker_number, $record->capacity);
             //setting trip dates
             $temp_trip->dates = new TripDates($record->email_date, $record->filling_date, $record->receiving_date, $record->stn_receiving_date, $record->decanding_date, $record->invoice_date, $record->entryDate);
             $temp_trip->invoice_number = $record->invoice_number;
         }
         /////////////////////////////////////////////////
         /////////////////////////////////////////////////
         if ($record->trips_details_id != $previous_trip_product_detail_id) {
             $previous_trip_product_detail_id = $record->trips_details_id;
             $temp_trip_product_detail = new Trip_Product_Detail($temp_trip);
             //setting data in the Trip_Product_Data object
             $temp_trip_product_detail->product_detail_id = $record->trips_details_id;
             $temp_trip_product_detail->product = new Product($record->productId, $record->productName, $record->product_type);
             $temp_trip_product_detail->source = new City($record->source_id, $record->sourceCityName);
             $temp_trip_product_detail->destination = new City($record->destination_id, $record->destinationCityName);
             $temp_trip_product_detail->product_quantity = $record->product_quantity;
             $temp_trip_product_detail->quantity_at_destination = $record->qty_at_destination;
             $temp_trip_product_detail->quantity_after_decanding = $record->qty_after_decanding;
             $temp_trip_product_detail->price_unit = $record->price_unit;
             $temp_trip_product_detail->customer_freight_unit = $record->freight_unit;
             $temp_trip_product_detail->company_freight_unit = $record->company_freight_unit;
             $temp_trip_product_detail->stn_number = $record->stn_number;
             $temp_trip_product_detail->shortage_voucher_dest = $record->shortage_voucher_dest;
             $temp_trip_product_detail->shortage_voucher_decnd = $record->shortage_voucher_decnd;
             //setting bill data
             $bill = new Bill();
             $bill->id = $record->bill_id;
             $bill->date_time = $record->billed_date_time;
             $temp_trip_product_detail->bill = $bill;
         }
         /////////////////////////////////////////////////
         //gathring data according to aimed for
         switch ($aimed_for) {
             case "contractor_accounts":
                 ///************Setting contractor commission credit Accounts**********///
                 if (!in_array($record->contractor_accounts_voucher_entry_id, $contractor_accounts_voucher_entry_ids)) {
                     $temp_contractor_accounts_voucher_entry = new Voucher_Entry();
                     //setting data in the parent object
                     $temp_contractor_accounts_voucher_entry->active = $record->contractor_accounts_voucher_active;
                     $temp_contractor_accounts_voucher_entry->setAc_type($record->contractor_accounts_voucher_entry_ac_type);
                     $temp_contractor_accounts_voucher_entry->setTitle($record->contractor_accounts_title);
                     $temp_contractor_accounts_voucher_entry->setAccount_title_id($record->contractor_accounts_title_id);
                     $agent_type = "";
                     $agent_id = 0;
                     if ($record->contractor_accounts_voucher_entry_related_other_agent != 0) {
                         $agent_id = $record->contractor_accounts_voucher_entry_related_other_agent;
                         $agent_type = "other_agent";
                     } else {
                         if ($record->contractor_accounts_voucher_entry_related_customer != 0) {
                             $agent_id = $record->contractor_accounts_voucher_entry_related_customer;
                             $agent_type = "customer";
                         } else {
                             if ($record->contractor_accounts_voucher_entry_related_contractor != 0) {
                                 $agent_id = $record->contractor_accounts_voucher_entry_related_contractor;
                                 $agent_type = "contractor";
                             } else {
                                 if ($record->contractor_accounts_voucher_entry_related_company != 0) {
                                     $agent_id = $record->contractor_accounts_voucher_entry_related_company;
                                     $agent_type = "company";
                                 }
                             }
                         }
                     }
                     $temp_contractor_accounts_voucher_entry->setRelated_agent($agent_type);
                     $temp_contractor_accounts_voucher_entry->setRelated_agent_id($agent_id);
                     $temp_contractor_accounts_voucher_entry->person_tid = $record->contractor_accounts_voucher_person_tid;
                     $temp_contractor_accounts_voucher_entry->setCredit($record->contractor_accounts_voucher_entry_credit_amount);
                     //$temp_contractor_accounts_voucher_entry->setRelated_person_tid($record->contractor_accounts_voucher_person_tid);
                 }
                 /////////////////////////////////////////////////
                 break;
             case "customer_accounts":
                 ///************Setting contractor commission credit Accounts**********///
                 if (!in_array($record->customer_accounts_voucher_entry_id, $customer_accounts_voucher_entry_ids)) {
                     $temp_customer_accounts_voucher_entry = new Voucher_Entry();
                     //setting data in the parent object
                     $temp_customer_accounts_voucher_entry->active = $record->customer_accounts_voucher_active;
                     $temp_customer_accounts_voucher_entry->setAc_type($record->customer_accounts_voucher_entry_ac_type);
                     $temp_customer_accounts_voucher_entry->setTitle($record->customer_accounts_title);
                     $temp_customer_accounts_voucher_entry->setAccount_title_id($record->customer_accounts_title_id);
                     $agent_type = "";
                     $agent_id = 0;
                     if ($record->customer_accounts_voucher_entry_related_other_agent != 0) {
                         $agent_id = $record->customer_accounts_voucher_entry_related_other_agent;
                         $agent_type = "other_agent";
                     } else {
                         if ($record->customer_accounts_voucher_entry_related_customer != 0) {
                             $agent_id = $record->customer_accounts_voucher_entry_related_customer;
                             $agent_type = "customer";
                         } else {
                             if ($record->customer_accounts_voucher_entry_related_contractor != 0) {
                                 $agent_id = $record->customer_accounts_voucher_entry_related_contractor;
                                 $agent_type = "contractor";
                             } else {
                                 if ($record->customer_accounts_voucher_entry_related_company != 0) {
                                     $agent_id = $record->customer_accounts_voucher_entry_related_company;
                                     $agent_type = "company";
                                 }
                             }
                         }
                     }
                     $temp_customer_accounts_voucher_entry->setRelated_agent($agent_type);
                     $temp_customer_accounts_voucher_entry->setRelated_agent_id($agent_id);
                     $temp_customer_accounts_voucher_entry->person_tid = $record->customer_accounts_voucher_person_tid;
                     $temp_customer_accounts_voucher_entry->setCredit($record->customer_accounts_voucher_entry_credit_amount);
                     //$temp_contractor_accounts_voucher_entry->setRelated_person_tid($record->contractor_accounts_voucher_person_tid);
                 }
                 /////////////////////////////////////////////////
                 break;
             case "company_accounts":
                 ///************Setting contractor commission credit Accounts**********///
                 if (!in_array($record->company_accounts_voucher_entry_id, $company_accounts_voucher_entry_ids)) {
                     $temp_company_accounts_voucher_entry = new Voucher_Entry();
                     //setting data in the parent object
                     $temp_company_accounts_voucher_entry->active = $record->company_accounts_voucher_active;
                     $temp_company_accounts_voucher_entry->setAc_type($record->company_accounts_voucher_entry_ac_type);
                     $temp_company_accounts_voucher_entry->setTitle($record->company_accounts_title);
                     $temp_company_accounts_voucher_entry->setAccount_title_id($record->company_accounts_title_id);
                     $agent_type = "";
                     $agent_id = 0;
                     if ($record->company_accounts_voucher_entry_related_other_agent != 0) {
                         $agent_id = $record->company_accounts_voucher_entry_related_other_agent;
                         $agent_type = "other_agent";
                     } else {
                         if ($record->company_accounts_voucher_entry_related_customer != 0) {
                             $agent_id = $record->company_accounts_voucher_entry_related_customer;
                             $agent_type = "customer";
                         } else {
                             if ($record->company_accounts_voucher_entry_related_contractor != 0) {
                                 $agent_id = $record->company_accounts_voucher_entry_related_contractor;
                                 $agent_type = "contractor";
                             } else {
                                 if ($record->company_accounts_voucher_entry_related_company != 0) {
                                     $agent_id = $record->company_accounts_voucher_entry_related_company;
                                     $agent_type = "company";
                                 }
                             }
                         }
                     }
                     $temp_company_accounts_voucher_entry->setRelated_agent($agent_type);
                     $temp_company_accounts_voucher_entry->setRelated_agent_id($agent_id);
                     $temp_company_accounts_voucher_entry->person_tid = $record->company_accounts_voucher_person_tid;
                     $temp_company_accounts_voucher_entry->setCredit($record->company_accounts_voucher_entry_credit_amount);
                     //$temp_contractor_accounts_voucher_entry->setRelated_person_tid($record->contractor_accounts_voucher_person_tid);
                 }
                 /////////////////////////////////////////////////
                 break;
             case "manage_accounts":
                 ///************Setting contractor commission credit Accounts**********///
                 //if(!in_array($record->manage_accounts_voucher_entry_id, $trip_detail_voucher_relation_for_manage_accounts_ids))
                 //{
                 $temp_manage_accounts_voucher_entry = new Voucher_Entry();
                 //setting data in the parent object
                 $temp_manage_accounts_voucher_entry->journal_voucher_id = $record->manage_accounts_voucher_id;
                 $temp_manage_accounts_voucher_entry->voucher_date = $record->manage_accounts_voucher_date;
                 $temp_manage_accounts_voucher_entry->active = $record->manage_accounts_voucher_active;
                 $temp_manage_accounts_voucher_entry->setAc_type($record->manage_accounts_voucher_entry_ac_type);
                 $temp_manage_accounts_voucher_entry->setTitle($record->manage_accounts_title);
                 $temp_manage_accounts_voucher_entry->setAccount_title_id($record->manage_accounts_title_id);
                 $temp_manage_accounts_voucher_entry->dr_cr = $record->manage_accounts_voucher_entry_dr_cr;
                 $agent_type = "";
                 $agent_id = 0;
                 if ($record->manage_accounts_voucher_entry_related_other_agent != 0) {
                     $agent_id = $record->manage_accounts_voucher_entry_related_other_agent;
                     $agent_type = "other_agent";
                 } else {
                     if ($record->manage_accounts_voucher_entry_related_customer != 0) {
                         $agent_id = $record->manage_accounts_voucher_entry_related_customer;
                         $agent_type = "customer";
                     } else {
                         if ($record->manage_accounts_voucher_entry_related_contractor != 0) {
                             $agent_id = $record->manage_accounts_voucher_entry_related_contractor;
                             $agent_type = "contractor";
                         } else {
                             if ($record->manage_accounts_voucher_entry_related_company != 0) {
                                 $agent_id = $record->manage_accounts_voucher_entry_related_company;
                                 $agent_type = "company";
                             }
                         }
                     }
                 }
                 $temp_manage_accounts_voucher_entry->setRelated_agent($agent_type);
                 $temp_manage_accounts_voucher_entry->setRelated_agent_id($agent_id);
                 $temp_manage_accounts_voucher_entry->person_tid = $record->manage_accounts_voucher_person_tid;
                 $temp_manage_accounts_voucher_entry->setCredit($record->manage_accounts_voucher_entry_credit_amount);
                 //$temp_contractor_accounts_voucher_entry->setRelated_person_tid($record->contractor_accounts_voucher_person_tid);
                 //}/////////////////////////////////////////////////
                 break;
             default:
                 break;
         }
         ///////////////////////////////////////////
         //pushing particals
         if ($count != sizeof($rawTrips)) {
             //pushing data according to aimed for
             switch ($aimed_for) {
                 case "contractor_accounts":
                     ///************Pushing contractor commission credit Accounts**********///
                     if (!in_array($record->contractor_accounts_voucher_entry_id, $contractor_accounts_voucher_entry_ids)) {
                         array_push($temp_trip_product_detail->contractor_accounts_entries, $temp_contractor_accounts_voucher_entry);
                         //pushing the object id
                         array_push($contractor_accounts_voucher_entry_ids, $record->contractor_accounts_voucher_entry_id);
                     }
                     /////////////////////////////////////////////////
                     break;
                 case "customer_accounts":
                     ///************Pushing contractor commission credit Accounts**********///
                     if (!in_array($record->customer_accounts_voucher_entry_id, $customer_accounts_voucher_entry_ids)) {
                         array_push($temp_trip_product_detail->customer_accounts_credit_entries, $temp_customer_accounts_voucher_entry);
                         //pushing the object id
                         array_push($customer_accounts_voucher_entry_ids, $record->customer_accounts_voucher_entry_id);
                     }
                     /////////////////////////////////////////////////
                     break;
                 case "company_accounts":
                     ///************Pushing contractor commission credit Accounts**********///
                     if (!in_array($record->company_accounts_voucher_entry_id, $company_accounts_voucher_entry_ids)) {
                         array_push($temp_trip_product_detail->customer_accounts_credit_entries, $temp_company_accounts_voucher_entry);
                         //pushing the object id
                         array_push($company_accounts_voucher_entry_ids, $record->company_accounts_voucher_entry_id);
                     }
                     /////////////////////////////////////////////////
                     break;
                 case "manage_accounts":
                     ///************Pushing contractor commission credit Accounts**********///
                     //if(!in_array($record->manage_accounts_voucher_entry_id, $trip_detail_voucher_relation_for_manage_accounts_ids)){
                     array_push($temp_trip_product_detail->user_accounts_entries, $temp_manage_accounts_voucher_entry);
                     //pushing the object id
                     array_push($trip_detail_voucher_relation_for_manage_accounts_ids, $record->manage_accounts_voucher_entry_id);
                     //}
                     /////////////////////////////////////////////////
                     break;
                 default:
                     break;
             }
             ///////////////////////////////////////////
             if ($rawTrips[$count]->trips_details_id != $record->trips_details_id) {
                 array_push($temp_trip->trip_related_details, $temp_trip_product_detail);
             }
             if ($rawTrips[$count]->trip_id != $record->trip_id) {
                 array_push($final_trips_array, $temp_trip);
             }
         } else {
             //pushing data according to aimed for
             switch ($aimed_for) {
                 case "contractor_accounts":
                     ///************Pushing contractor commission credit Accounts**********///
                     if (!in_array($record->contractor_accounts_voucher_entry_id, $contractor_accounts_voucher_entry_ids)) {
                         array_push($temp_trip_product_detail->contractor_accounts_entries, $temp_contractor_accounts_voucher_entry);
                     }
                     /////////////////////////////////////////////////
                     break;
                 case "customer_accounts":
                     ///************Pushing contractor commission credit Accounts**********///
                     if (!in_array($record->customer_accounts_voucher_entry_id, $customer_accounts_voucher_entry_ids)) {
                         array_push($temp_trip_product_detail->customer_accounts_credit_entries, $temp_customer_accounts_voucher_entry);
                     }
                     /////////////////////////////////////////////////
                     break;
                 case "company_accounts":
                     ///************Pushing contractor commission credit Accounts**********///
                     if (!in_array($record->company_accounts_voucher_entry_id, $company_accounts_voucher_entry_ids)) {
                         array_push($temp_trip_product_detail->customer_accounts_credit_entries, $temp_company_accounts_voucher_entry);
                     }
                     /////////////////////////////////////////////////
                     break;
                 case "manage_accounts":
                     ///************Pushing contractor commission credit Accounts**********///
                     //if(!in_array($record->manage_accounts_voucher_entry_id, $trip_detail_voucher_relation_for_manage_accounts_ids)){
                     array_push($temp_trip_product_detail->user_accounts_entries, $temp_manage_accounts_voucher_entry);
                     //}
                     /////////////////////////////////////////////////
                     break;
                 default:
                     break;
             }
             ///////////////////////////////////////////
             array_push($temp_trip->trip_related_details, $temp_trip_product_detail);
             array_push($final_trips_array, $temp_trip);
         }
     }
     return $final_trips_array;
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
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);
 }