app/models/receipt.rb
def preset_default_values( params_hash = {} )
    unless self.patient                             # Set current patient only if not set
      begin
        if params_hash[:patient_id]
          self.patient_id = params_hash[:patient_id].to_i
        end
      rescue
        self.patient_id = nil
      end
    end
                                                    # If patient is set and price not, get the default price:
    unless self.receipt_description
      if (self.patient_id.to_i > 0) && (p = Patient.find(self.patient_id))
        self.price = p.default_invoice_price unless (self.price.to_f > 0.0)
        self.receipt_description = p.default_invoice_text if self.receipt_description.blank? && (! p.default_invoice_text.blank?)
      end
                                                    # Set the default description if not yet set:
      self.receipt_description = Receipt.get_default_receipt_description(self) unless self.receipt_description
    end

    unless self.date_receipt                        # A default date_receipt must be set anyhow:
      begin                   
          self.date_receipt = params_hash[:date_receipt] ? params_hash[:date_receipt] : Time.now
      rescue                                        # Set default date for this entry:
        self.date_receipt = Time.now
      end
    end

    self.receipt_num = Receipt.get_next_receipt_num() unless (self.receipt_num > 0)
    self.is_receipt_delivered ||= 0
    # [Steve, 20100915] Known issue: we cannot set automatically or directly the "is_payed" flag (for instance,
    # reading the corresponding flag on any issuing appointment row) since this acts as a global "is_payed" status
    # for the whole due amount and - also - there may be more than 1 appointment rows linked to this receipt
    # (and the patient could be paying just a partial sum on each appointment).
    # So this needs to be cleared on start, until the whole receipt has been effectively "payed" (the user toggles it).
    self.is_payed ||= 0
    self
  end
# Checks and sets fields value defaults.
#
# === Parameters:
# - +params_hash+ => Hash of additional parameter values for attribute defaults override.
#
Checks and sets fields value defaults.
Parameters:
+params_hash+ => Hash of additional parameter values for attribute defaults override.
Checks and sets fields value defaults . Parameters : + params_hash + = > Hash of additional parameter values for attribute defaults override .
def preset_default_values( params_hash = {} )
    unless self.patient                             
      begin
        if params_hash[:patient_id]
          self.patient_id = params_hash[:patient_id].to_i
        end
      rescue
        self.patient_id = nil
      end
    end
    unless self.receipt_description
      if (self.patient_id.to_i > 0) && (p = Patient.find(self.patient_id))
        self.price = p.default_invoice_price unless (self.price.to_f > 0.0)
        self.receipt_description = p.default_invoice_text if self.receipt_description.blank? && (! p.default_invoice_text.blank?)
      end
      self.receipt_description = Receipt.get_default_receipt_description(self) unless self.receipt_description
    end
    unless self.date_receipt                        
      begin                   
          self.date_receipt = params_hash[:date_receipt] ? params_hash[:date_receipt] : Time.now
      rescue                                        
        self.date_receipt = Time.now
      end
    end
    self.receipt_num = Receipt.get_next_receipt_num() unless (self.receipt_num > 0)
    self.is_receipt_delivered ||= 0
    self.is_payed ||= 0
    self
  end
def preset_default_values ( params_hash = { } ) unless self . patient begin if params_hash [ :patient_id ] self . patient_id = params_hash [ :patient_id ] . to_i end rescue self . patient_id = nil end end unless self . receipt_description if ( self . patient_id . to_i > 0 ) && ( p = Patient . find ( self . patient_id ) ) self . price = p . default_invoice_price unless ( self . price . to_f > 0.0 ) self . receipt_description = p . default_invoice_text if self . receipt_description . blank? && ( ! p . default_invoice_text . blank? ) end self . receipt_description = Receipt . get_default_receipt_description ( self ) unless self . receipt_description end unless self . date_receipt begin self . date_receipt = params_hash [ :date_receipt ] ? params_hash [ :date_receipt ] : Time . now rescue self . date_receipt = Time . now end end self . receipt_num = Receipt . get_next_receipt_num ( ) unless ( self . receipt_num > 0 ) self . is_receipt_delivered ||= 0 self . is_payed ||= 0 self end
Checks and sets fields value defaults.
Checks and sets fields value defaults .
# Set current patient only if not set # If patient is set and price not, get the default price: # Set the default description if not yet set: # A default date_receipt must be set anyhow: # Set default date for this entry: # [Steve, 20100915] Known issue: we cannot set automatically or directly the "is_payed" flag (for instance, # reading the corresponding flag on any issuing appointment row) since this acts as a global "is_payed" status # for the whole due amount and - also - there may be more than 1 appointment rows linked to this receipt # (and the patient could be paying just a partial sum on each appointment). # So this needs to be cleared on start, until the whole receipt has been effectively "payed" (the user toggles it).
params_hash