-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #292 from Purple-Stock/staging
update the productions
- Loading branch information
Showing
6 changed files
with
177 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,97 @@ | ||
<%= form_with(model: production, local: true) do |form| %> | ||
<%# app/views/productions/_form.html.erb %> | ||
|
||
<!-- Fields for production --> | ||
<%= form_with(model: [@account, production], local: true) do |form| %> | ||
<% if production.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(production.errors.count, "error") %> prohibited this production from being saved:</h2> | ||
<ul> | ||
<% production.errors.full_messages.each do |message| %> | ||
<li><%= message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="form-group"> | ||
<%= form.label :number %> | ||
<%= form.number_field :number, class: 'form-control' %> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= form.label :tailor_id, 'Select Tailor' %> | ||
<%= form.collection_select :tailor_id, Tailor.all, :id, :name, include_blank: true %> | ||
<%= form.collection_select :tailor_id, Tailor.all, :id, :name, { include_blank: true }, { class: 'form-control' } %> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= form.label :cut_date %> | ||
<%= form.date_field :cut_date, class: 'form-control' %> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= form.label :delivery_date %> | ||
<%= form.date_field :delivery_date, class: 'form-control' %> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= form.label :pieces_delivered %> | ||
<%= form.number_field :pieces_delivered, class: 'form-control' %> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= form.label :pieces_missing %> | ||
<%= form.number_field :pieces_missing, class: 'form-control' %> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= form.label :expected_delivery_date %> | ||
<%= form.date_field :expected_delivery_date, class: 'form-control' %> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= form.label :confirmed %> | ||
<%= form.check_box :confirmed, class: 'form-check-input' %> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= form.label :paid %> | ||
<%= form.check_box :paid, class: 'form-check-input' %> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= form.label :consider %> | ||
<%= form.check_box :consider, class: 'form-check-input' %> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= form.label :observation %> | ||
<%= form.text_area :observation, class: 'form-control' %> | ||
</div> | ||
|
||
<h3>Products</h3> | ||
<div id="products"> | ||
<%= form.fields_for :products do |product_form| %> | ||
<%= render 'product_fields', f: product_form %> | ||
<%= form.fields_for :production_products do |production_product_form| %> | ||
<%= render 'production_product_fields', f: production_product_form %> | ||
<% end %> | ||
|
||
<div class="links"> | ||
<%= link_to_add_association 'Add Product', form, :products %> | ||
<%= link_to_add_association 'Add Product', form, :production_products, partial: 'production_product_fields' %> | ||
</div> | ||
</div> | ||
|
||
<%= form.submit %> | ||
<%= form.submit class: 'btn btn-primary' %> | ||
<% end %> | ||
|
||
<%# app/views/productions/_production_product_fields.html.erb %> | ||
<div class="nested-fields"> | ||
<div class="form-group"> | ||
<%= f.label :product_id, 'Select Product' %> | ||
<%= f.collection_select :product_id, Product.all, :id, :name, { include_blank: true }, { class: 'form-control' } %> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= f.label :quantity %> | ||
<%= f.number_field :quantity, class: 'form-control' %> | ||
</div> | ||
|
||
<%= link_to_remove_association "Remove Product", f %> | ||
</div> |
31 changes: 12 additions & 19 deletions
31
app/views/productions/_production_product_fields.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,15 @@ | ||
<div class="nested-fields"> | ||
<div class="col-md-12"> | ||
<div class="row mb-3"> | ||
<!-- Product Select Dropdown --> | ||
<div class="col-md-6"> | ||
<%= f.label :product_id, t('activerecord.attributes.production_product.product_id') %> | ||
<%= f.collection_select :product_id, Product.all, :id, :name, { include_blank: true }, { class: 'form-control' } %> | ||
</div> | ||
|
||
<!-- Quantity Input --> | ||
<div class="col-md-2"> | ||
<%= f.label :quantity, t('activerecord.attributes.production_product.quantity') %> | ||
<%= f.number_field :quantity, class: 'form-control' %> | ||
</div> | ||
|
||
<!-- Remove Button --> | ||
<div class="col-md-2 d-flex align-items-end"> | ||
<%= link_to_remove_association t('actions.remove_product'), f, class: 'btn btn-danger' %> | ||
</div> | ||
<div class="row"> | ||
<div class="col-md-6"> | ||
<%= f.label :product_id, ProductionProduct.human_attribute_name(:product), class: 'form-label' %> | ||
<%= f.collection_select :product_id, Product.all, :id, :name, { include_blank: true }, { class: 'form-control', required: true } %> | ||
</div> | ||
<div class="col-md-4"> | ||
<%= f.label :quantity, ProductionProduct.human_attribute_name(:quantity), class: 'form-label' %> | ||
<%= f.number_field :quantity, class: 'form-control', min: 1, required: true %> | ||
</div> | ||
<div class="col-md-2 d-flex align-items-end"> | ||
<%= link_to_remove_association t('actions.remove'), f, class: 'btn btn-danger' %> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
db/migrate/20240828195207_add_missing_fields_to_productions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class AddMissingFieldsToProductions < ActiveRecord::Migration[7.0] | ||
def change | ||
change_table :productions, bulk: true do |t| | ||
t.column :number, :integer, if_not_exists: true | ||
t.column :delivery_date, :date, if_not_exists: true | ||
t.column :pieces_delivered, :integer, if_not_exists: true | ||
t.column :pieces_missing, :integer, if_not_exists: true | ||
t.column :expected_delivery_date, :date, if_not_exists: true | ||
t.column :confirmed, :boolean, if_not_exists: true | ||
t.column :paid, :boolean, if_not_exists: true | ||
t.column :observation, :text, if_not_exists: true | ||
|
||
# Add indexes | ||
t.index :number, if_not_exists: true | ||
t.index :cut_date, if_not_exists: true | ||
t.index :delivery_date, if_not_exists: true | ||
t.index :expected_delivery_date, if_not_exists: true | ||
end | ||
|
||
# Add foreign key for account if it doesn't exist | ||
unless foreign_key_exists?(:productions, :accounts) | ||
add_foreign_key :productions, :accounts | ||
end | ||
|
||
# Add foreign key for tailor if it doesn't exist | ||
unless foreign_key_exists?(:productions, :tailors) | ||
add_foreign_key :productions, :tailors | ||
end | ||
end | ||
end |