}
 }
 public function add_company_payment()
 {
     $payment_date = easyDate($this->input->post('payment_date')) == '1970-01-01' ? '0000-00-00' : easyDate($this->input->post('payment_date'));
     $data = array('trip_id' => $this->input->post('trip_id'), 'company_id' => $this->input->post('company_id'), 'payment_date' => $payment_date, 'amount' => $this->input->post('amount'), 'entryDate' => $this->carbon->now(new DateTimeZone('Asia/Karachi'))->toDateTimeString());
     $result = $this->db->insert('company_accounts', $data);
     if ($result == true) {
         return true;
     } else {
         return false;
Ejemplo n.º 2
0
 public function profit_loss($tanker_id = '', $from_date = '', $to_date = '')
 {
     if ($tanker_id == '') {
         $this->index();
     } else {
         $headerData = array('title' => 'Virik-Logistics | Tankers | profit & Loss', 'page' => 'tankers');
         $bodyData = array('profile' => $this->tankers_model->tanker($tanker_id), 'trips_expenses' => '', 'other_tanker_expenses' => '', 'revenues' => '', 'remaining' => 0, 'paid' => 0, 'total_tanker_expense_trips' => 0, 'total_tanker_expense_other' => 0, 'total_driver_expense_trips' => 0, 'total_pd_expense_trips' => 0, 'total_revenue' => 0, 'total_freight' => 0, 'from_date' => '', 'to_date' => '');
         $from = $from_date;
         $to = $to_date;
         if ($from == '' || $to == '') {
             $from = date('Y-m') . "-01";
             $to = date('Y-m') . "-" . date('t');
         } else {
             if ($this->helper_model->bigger_date(easyDate($from), easyDate($to))) {
                 $temp_to = $to;
                 $to = $from;
                 $from = $temp_to;
             }
             //converting date formats
             $to = easyDate($to);
             $from = easyDate($from);
         }
         //computing bodyData
         $bodyData['trips_expenses'] = $this->profit_loss_model->tanker_trips_expenses($bodyData['profile']->customerId, $tanker_id, $from, $to);
         foreach ($bodyData['trips_expenses'] as $expense) {
             $bodyData['total_tanker_expense_trips'] += $expense->tanker_expense;
             $bodyData['total_driver_expense_trips'] += $expense->drivers_expense;
             $bodyData['total_pd_expense_trips'] += $expense->pd_expense;
         }
         $bodyData['other_tanker_expenses'] = $this->profit_loss_model->tanker_other_expenses($tanker_id, $from, $to);
         foreach ($bodyData['other_tanker_expenses'] as $expense) {
             $bodyData['total_tanker_expense_other'] += $expense->amount;
         }
         $bodyData['revenues'] = $this->profit_loss_model->tanker_trips_revenues($bodyData['profile']->customerId, $tanker_id, $from, $to);
         foreach ($bodyData['revenues'] as $revenue) {
             $bodyData['total_freight'] += $revenue->total_freight;
             $bodyData['total_revenue'] += $revenue->net_freight;
             $bodyData['paid'] += $revenue->paid;
             $bodyData['remaining'] += $revenue->remaining;
         }
         $bodyData['from_date'] = $from;
         $bodyData['to_date'] = $to;
         if (isset($_GET['print'])) {
             $this->load->view('tankers/components/print_profit_loss', $bodyData);
         } else {
             $this->load->view('components/header', $headerData);
             $this->load->view('tankers/profit_loss', $bodyData);
             $this->load->view('components/footer');
         }
     }
 }
Ejemplo n.º 3
0
 public function update_other_trip($trip_id = '', $trip_type)
 {
     $details_counter = $this->input->post('pannel_count');
     //setting dates
     $entry_date = easyDate($this->input->post('entry_date')) == '1970-01-01' ? '0000-00-00' : easyDate($this->input->post('entry_date'));
     $email_date = easyDate($this->input->post('email_date')) == '1970-01-01' ? '0000-00-00' : easyDate($this->input->post('email_date'));
     $filling_date = easyDate($this->input->post('filling_date')) == '1970-01-01' ? '0000-00-00' : easyDate($this->input->post('filling_date'));
     $receiving_date = easyDate($this->input->post('receiving_date')) == '1970-01-01' ? '0000-00-00' : easyDate($this->input->post('receiving_date'));
     $stn_receiving_date = easyDate($this->input->post('stn_receiving_date')) == '1970-01-01' ? '0000-00-00' : easyDate($this->input->post('stn_receiving_date'));
     $decanding_date = easyDate($this->input->post('decanding_date')) == '1970-01-01' ? '0000-00-00' : easyDate($this->input->post('decanding_date'));
     //echo "<h1>".$decanding_date."</h1>";
     $invoice_date = easyDate($this->input->post('invoice_date')) == '1970-01-01' ? '0000-00-00' : easyDate($this->input->post('invoice_date'));
     $trips_data = array('customer_id' => $this->input->post('customers'), 'contractor_id' => $this->input->post('contractors'), 'company_id' => $this->input->post('companies'), 'tanker_id' => $this->input->post('tankers'), 'contractor_commission' => $this->input->post('contractor_commission'), 'company_commission_1' => $this->input->post('company_commission_1'), 'company_commission_2' => $this->input->post('company_commission_2'), 'entryDate' => $entry_date, 'email_date' => $email_date, 'filling_date' => $filling_date, 'receiving_date' => $receiving_date, 'stn_receiving_date' => $stn_receiving_date, 'decanding_date' => $decanding_date, 'invoice_date' => $invoice_date, 'driver_id_1' => $this->input->post('drivers_1'), 'driver_id_2' => $this->input->post('drivers_2'), 'driver_id_3' => $this->input->post('drivers_3'), 'invoice_number' => $this->input->post('invoice_number'), 'start_meter' => $this->input->post('start_meter_reading'), 'end_meter' => $this->input->post('end_meter_reading'), 'fuel_consumed' => $this->input->post('fuel_consumed'), 'type' => $this->input->post('trip_type'));
     //deciding weather to update or insert?
     $db_error = true;
     $inserted_trip_id = 0;
     if ($trip_id == '') {
         $trips_insert_result = $this->db->insert('trips', $trips_data);
         if ($trips_insert_result == true) {
             $inserted_trip_id = $this->db->insert_id();
             $db_error = false;
         }
     } else {
         $this->db->where('trips.id', $trip_id);
         $this->db->update('trips', $trips_data);
     }
     $trips_details_data = array();
     $trip_details_ids = array();
     for ($counter = 1; $counter < $details_counter; $counter++) {
         //calculating qty_at_destination adn after_decanding
         $initial_quantity = $this->input->post('initial_product_quantity_' . $counter) != '' ? $this->input->post('initial_product_quantity_' . $counter) : 0;
         $shortage_at_destination = $this->input->post('shortage_at_destination_' . $counter) ? $this->input->post('shortage_at_destination_' . $counter) : 0;
         $shortage_after_decanding = $this->input->post('shortage_after_decanding_' . $counter) ? $this->input->post('shortage_after_decanding_' . $counter) : 0;
         $quantity_at_destination = $initial_quantity - $shortage_at_destination;
         $quantity_after_decanding = $quantity_at_destination - $shortage_after_decanding;
         $company_freight_unit = $this->input->post('company_freight_unit_' . $counter) == '' ? $this->input->post('freight_unit_' . $counter) : $this->input->post('company_freight_unit_' . $counter);
         //finding necessary reqs //
         switch ($trip_type) {
             case "local_cmp":
                 $route_id = $this->input->post('route_' . $counter);
                 $route = $this->routes_model->route($route_id);
                 $source_id = $route->sourceId;
                 $destination_id = $route->destinationId;
                 $product_id = $route->productId;
                 break;
             case "local_self":
                 $route_id = $this->input->post('route_' . $counter);
                 $route = $this->routes_model->route($route_id);
                 $source_id = $route->sourceId;
                 $destination_id = $route->destinationId;
                 $product_id = $route->productId;
                 break;
         }
         /////////////////////////
         $arr = array('trip_id' => $trip_id == '' ? $inserted_trip_id : $trip_id, 'source' => $source_id, 'destination' => $destination_id, 'product' => $product_id, 'product_quantity' => $this->input->post('initial_product_quantity_' . $counter), 'qty_at_destination' => $quantity_at_destination, 'qty_after_decanding' => $quantity_after_decanding, 'price_unit' => $this->input->post('price_unit_' . $counter), 'freight_unit' => $this->input->post('freight_unit_' . $counter), 'company_freight_unit' => $company_freight_unit, 'stn_number' => $this->input->post('stn_number_' . $counter));
         $trips_details_data_for_insertion_at_updation_time = array();
         //below segment will execute when trip was edited..
         if ($trip_id != '') {
             //below we check weather this record should b updated or inserted...
             if ($counter > $this->input->post('num_saved_trips_details')) {
                 array_unshift($trips_details_data_for_insertion_at_updation_time, $arr);
             }
             $arr['id'] = $this->input->post('trips_details_id_' . $counter);
             array_push($trip_details_ids, $this->input->post('trips_details_id_' . $counter));
         }
         array_unshift($trips_details_data, $arr);
     }
     /*
      * -----------------------------------
      * 4/9/2015 | Delete Trip Details
      * -----------------------------------
      * deleting those details which user
      * wants to be deleted.
      * */
     //deleting details
     $this->db->where_not_in('trips_details.id', $trip_details_ids);
     $this->db->where('trips_details.trip_id', $trip_id);
     $this->db->from('trips_details');
     $this->db->delete();
     //deleting vouchers
     $this->db->where_not_in('voucher_journal.trip_product_detail_id', $trip_details_ids);
     $this->db->where('voucher_journal.trip_id', $trip_id);
     $this->db->where('voucher_journal.auto_generated', 1);
     $voucher_data = array('active' => 0);
     $this->db->update('voucher_journal', $voucher_data);
     /*---------------------~Ends~------------------------------*/
     //deciding weather to update or insert?
     if (sizeof($trips_details_data_for_insertion_at_updation_time) >= 1) {
         $result = $this->db->insert_batch('trips_details', $trips_details_data_for_insertion_at_updation_time);
     }
     $result = $this->db->update_batch('trips_details', $trips_details_data, 'id');
     return true;
 }
Ejemplo n.º 4
0
 public function generate_company_reports()
 {
     $contractor_id = $this->input->get('contractors');
     $customer_id = $this->input->get('customers');
     $company_id = $this->input->get('companies');
     $tanker_id = $this->input->get('tankers');
     $from_date = new DateTime(easyDate($this->input->get('from_date')));
     $to_date = new DateTime(easyDate($this->input->get('to_date')));
     if ($from_date < $to_date) {
         $smaller_date = $from_date->format('Y-m-d');
         $bigger_date = $to_date->format('Y-m-d');
     } else {
         $smaller_date = $to_date->format('Y-m-d');
         $bigger_date = $from_date->format('Y-m-d');
     }
     if ($tanker_id != 'all') {
         $this->db->where('trips.tanker_id', $tanker_id);
     }
     if ($customer_id != 'all') {
         $this->db->where('tankers.customerId', $customer_id);
     }
     $this->db->where(array('trips.contractor_id' => $contractor_id, 'trips.company_id' => $company_id, 'trips.entryDate >=' => $smaller_date, 'trips.entryDate <=' => $bigger_date));
     $this->db->select('trips.id as trip_id');
     $this->db->from('trips');
     $this->db->where('trips.active', 1);
     /*$this->db->join('trips_details','trips_details.trip_id = trips.id');
       $this->db->join('tankers', 'tankers.id = trips.tanker_id');
       $this->db->join('customers', 'customers.id = tankers.customerId');
       $this->db->join('companies', 'companies.id = trips.company_id');
       //$this->db->join('routes', 'routes.id = trips.route_id');
       $this->db->join('cities as source_city', 'source_city.id = trips_details.source');
       $this->db->join('cities as destin_city', 'destin_city.id = trips_details.destination');
       //$this->db->order_by("source_city.cityName","asc");
       //$this->db->order_by("trips_details.stn_number","asc");
       $this->db->order_by("trips_details.trip_id","asc");*/
     $this->db->order_by('trips.entryDate', 'asc');
     $reports = $this->db->get()->result();
     $reports_details = array();
     foreach ($reports as $report) {
         array_push($reports_details, $this->trips_model->trip_details($report->trip_id));
     }
     usort($reports_details, array("Reports_Model", "cmp_company_report_route_stn"));
     return $reports_details;
 }
Ejemplo n.º 5
0
 public function save_route()
 {
     $route_id = $this->input->post('route_id');
     $freight = $this->input->post('freight');
     $source = $this->input->post('source');
     $destination = $this->input->post('destination');
     $product = $this->input->post('product');
     $startDate = easyDate($this->input->post('from'));
     $endDate = easyDate($this->input->post('to'));
     $previous_freight = $this->input->post('previous_freight');
     $previous_from = $this->input->post('previous_from');
     $previous_to = $this->input->post('previous_to');
     $freight_id = $this->input->post('freight_id');
     $freight_data = array('route_id' => $route_id, 'freight' => $freight, 'startDate' => $startDate, 'endDate' => $endDate);
     $route_data = array('source' => $source, 'destination' => $destination, 'product' => $product);
     $this->db->where('id', $route_id);
     if ($this->db->update('routes', $route_data) == true) {
         $this->db->where(array('id' => $freight_id));
         if ($this->db->insert('freights', $freight_data) == true) {
             $this->db->select("trips.id as trip_id");
             $this->db->distinct();
             $this->db->from('trips');
             $this->db->join('trips_details', 'trips_details.trip_id = trips.id', 'left');
             $this->db->where(array('trips_details.source' => $source, 'trips_details.destination' => $destination, 'trips_details.product' => $product, 'trips.filling_date >=' => $startDate, 'trips.filling_date <=' => $endDate));
             $trips = $this->db->get()->result();
             $trip_ids = array();
             if (sizeof($trips) > 0) {
                 foreach ($trips as $trip) {
                     array_push($trip_ids, $trip->trip_id);
                 }
                 /*
                  * --------------------------------------------
                  *  Checking if the freight is used in trips
                  *  with mass payments.
                  * --------------------------------------------
                  */
                 $this->db->select('trips_details.id as detail_id');
                 $this->db->where_in('trips_details.trip_id', $trip_ids);
                 $raw_trip_detail_ids = $this->db->get('trips_details')->result();
                 $trip_detail_ids = array();
                 foreach ($raw_trip_detail_ids as $detail) {
                     array_push($trip_detail_ids, $detail->detail_id);
                 }
                 $this->db->select('trip_detail_voucher_relation.voucher_id');
                 $this->db->from('trip_detail_voucher_relation');
                 $this->db->join('voucher_journal', 'voucher_journal.id = trip_detail_voucher_relation.voucher_id', 'left');
                 $this->db->where_in('trip_detail_voucher_relation.trip_detail_id', $trip_detail_ids);
                 $this->db->where(array('voucher_journal.active' => 1, 'voucher_journal.auto_generated' => 0, 'voucher_journal.transaction_column !=' => ''));
                 $mass_payament_trips = $this->db->get()->num_rows();
                 /*-----------------------------------------------*/
                 /*
                                      *  ----------------------------------------
                                      *        CHECK TRIPS MASS PAYMENTS
                                      *  ----------------------------------------
                                      *  if there are trips with mass payment
                                      *  happened on them with the current
                                      *  updating route, then dont update
                                      *  company freight per unit in the trips
                                      *  table.
                                      *
                                     \* -----------------------------------------*/
                 if ($mass_payament_trips > 0) {
                     return true;
                 } else {
                     $trips_data = array('trips_details.company_freight_unit' => $freight);
                     $this->db->where_in('trips_details.trip_id', $trip_ids);
                     if ($this->db->update('trips_details', $trips_data) == true) {
                         return true;
                     }
                 }
                 /*~~~~~~~~~~~~~~ CHECKING ENDS ~~~~~~~~~~~~~*/
             } else {
                 return true;
             }
         }
     }
     /*if($freight == $previous_freight){
           $data = array(
               'source'=>$source,
               'destination'=>$destination,
               'product'=>$product,
           );
           $this->db->where('id',$route_id);
           if($this->db->update('routes', $data) == true){
               $this->db->where(array('id'=>$freight_id,));
               if($this->db->update('freights',$freight_data) == true)
               return true;
           }
       }else{
           $routes_data = array(
               'source'=>$source,
               'destination'=>$destination,
               'product'=>$product,
           );
           $this->db->where('id',$route_id);
           $this->db->update('routes', $routes_data);
           $this->db->insert('freights', $freight_data);
           return true;
       }*/
     return false;
 }
Ejemplo n.º 6
0
 public function add_other_expense($tanker_id)
 {
     $expense_date = easyDate($this->input->post('expense_date'));
     $amount = $this->input->post('amount');
     $title = $this->input->post('expense_title');
     $tanker_id = $tanker_id;
     $data = array('tanker_id' => $tanker_id, 'expense_date' => $expense_date, 'description' => $title, 'amount' => $amount, 'entryDate' => $this->carbon->now(new DateTimeZone('Asia/Karachi'))->toDateTimeString());
     $result = $this->db->insert('other_tankers_expenses', $data);
     return $result == 1 ? true : false;
 }
Ejemplo n.º 7
0
 public function add_trip_expense($id)
 {
     $data = array('driver_id' => $id, 'trip_id' => $this->input->post('trip_id'), 'expense_date' => easyDate($this->input->post('expense_date')), 'description' => $this->input->post('description'), 'amount' => $this->input->post('amount'), 'entryDate' => $this->carbon->now(new DateTimeZone('Asia/Karachi'))->toDateTimeString());
     $result = $this->db->insert('trips_drivers_expenses', $data);
     if ($result == true) {
         return true;
     } else {
         return false;
     }
 }