def verify_invoice_packages
      
      Caboose.log("Verifying invoice packages....")
      
      # See if any there are any empty invoice packages          
      self.invoice_packages.each do |ip|
        count = 0
        self.line_items.each do |li|
          count = count + 1 if li.invoice_package_id == ip.id
        end
        ip.destroy if count == 0
      end
      
      # See if any line items aren't associated with an invoice package
      line_items_attached = true      
      self.line_items.each do |li|
        line_items_attached = false if li.invoice_package_id.nil?
      end
      shipping_packages_attached = true
      self.invoice_packages.each do |ip|    
        shipping_packages_attached = false if ip.shipping_package_id.nil?                          
      end
      ips = self.invoice_packages
      if ips.count == 0 || !line_items_attached || !shipping_packages_attached        
        self.calculate
        LineItem.where(:invoice_id => self.id).update_all(:invoice_package_id => nil)
        InvoicePackage.where(:invoice_id => self.id).destroy_all          
        self.create_invoice_packages
      end
                  
    end
def verify_invoice_packages
      
      Caboose.log("Verifying invoice packages....")
      
      # See if any there are any empty invoice packages          
      self.invoice_packages.each do |ip|
        count = 0
        self.line_items.each do |li|
          count = count + 1 if li.invoice_package_id == ip.id
        end
        ip.destroy if count == 0
      end
      
      # See if any line items aren't associated with an invoice package
      line_items_attached = true      
      self.line_items.each do |li|
        line_items_attached = false if li.invoice_package_id.nil?
      end
      shipping_packages_attached = true
      self.invoice_packages.each do |ip|    
        shipping_packages_attached = false if ip.shipping_package_id.nil?                          
      end
      ips = self.invoice_packages
      if ips.count == 0 || !line_items_attached || !shipping_packages_attached        
        self.calculate
        LineItem.where(:invoice_id => self.id).update_all(:invoice_package_id => nil)
        InvoicePackage.where(:invoice_id => self.id).destroy_all          
        self.create_invoice_packages
      end
                  
    end
===========================================================================