diff --git a/plugins/bsc/public/contracts.js b/plugins/bsc/public/contracts.js
new file mode 100644
index 0000000..f7cd6cb
--- /dev/null
+++ b/plugins/bsc/public/contracts.js
@@ -0,0 +1,86 @@
+var BSCContracts = {};
+
+(function($){
+ BSCContracts.onDelete = function(item){
+ $('.token-input-dropdown').hide();
+ $('#bsc-plugin-row-'+item.sale_id.toString()).remove();
+ BSCContracts.updateTotal();
+ };
+
+ BSCContracts.onAdd = function(item){
+ var quantity = $('#bsc-plugin-sale-'+item.sale_id.toString()+'-quantity');
+ var price = $('#bsc-plugin-sale-'+item.sale_id.toString()+'-price');
+ quantity.addClass('required');
+ price.addClass('required');
+ quantity.val(1);
+ price.val(item.product_price);
+ BSCContracts.updateTotal();
+ };
+
+ BSCContracts.newID = function(){
+ if ( !this.idNum ) this.idNum = 0;
+ return this.idNum++;
+ };
+
+ BSCContracts.newProductLine = function(item){
+ var id = this.newID();
+ var tr = $('
');
+ var tds = $(' | | '+this.currencyUnit+' | ').appendTo(tr);
+ var input = $('').appendTo(tds[0]);
+ var searchUrl = this.searchUrl
+ .replace('ENTERPRISES', $('#involved-enterprises').val())
+ .replace('SALE_ID', id)
+ .replace('ADDED_PRODUCTS', $.map($('.search-product-field'), function(item){return item.value}).join(','));
+ var prePopulation = [];
+ var quantity = '';
+ var price = '';
+ var required = '';
+ if(item) {
+ item.sale_id = id;
+ prePopulation = [item];
+ quantity = item.quantity;
+ price = item.product_price;
+ required = 'required';
+ }
+ var opts = $.extend( { prePopulate: prePopulation, queryParam: input[0].name }, this.tokenInputOptions );
+
+ input.keydown(function(event){ if(event.keyCode == '13') return false })
+ .tokenInput(searchUrl, opts);
+ $('#bsc-plugin-contract-total-row').before(tr);
+ $('').appendTo(tds[1]);
+ $('').appendTo(tds[2]);
+ };
+
+ BSCContracts.prePopulate = function(items){
+ $(items).each(function(index, item){BSCContracts.newProductLine(item)});
+ }
+
+ BSCContracts.updateTotal = function(){
+ var total = 0;
+ var quantity = 0;
+ var price = 0;
+ $('.bsc-plugin-sales-product').each(function(index){
+ quantity = $('#' + $(this).attr('id') + " .bsc-plugin-sales-quantity").val();
+ price = $('#'+$(this).attr('id') + " .bsc-plugin-sales-price").val();
+ total += quantity*price;
+ });
+ $('#bsc-plugin-sales-total-value').text(BSCContracts.currencyUnit+' '+total);
+ }
+
+ $(".bsc-plugin-sales-price, .bsc-plugin-sales-quantity").live('change', function(e){
+ BSCContracts.updateTotal();
+ });
+
+ $("#bsc-plugin-add-new-product").click(function(){
+ var last = $('.search-product-field:last');
+ if(!last.val() && last.size() != 0){
+ last.focus();
+ return false;
+ }
+ var next_id = parseInt(last.attr('data-sale-id'))+1;
+ var enterprises = $('#involved-enterprises').val().replace(/,/g,'-');
+ BSCContracts.newProductLine();
+ return false;
+ });
+
+})(jQuery);
diff --git a/plugins/bsc/public/datepicker.js b/plugins/bsc/public/datepicker.js
new file mode 100644
index 0000000..3e9ff11
--- /dev/null
+++ b/plugins/bsc/public/datepicker.js
@@ -0,0 +1,14 @@
+var dates = jQuery( "#from, #to" ).datepicker({
+ defaultDate: "+1w",
+ changeMonth: true,
+ dateFormat: 'yy-mm-dd',
+ onSelect: function( selectedDate ) {
+ var option = this.id == "from" ? "minDate" : "maxDate",
+ instance = jQuery( this ).data( "datepicker" ),
+ date = jQuery.datepicker.parseDate(
+ instance.settings.dateFormat ||
+ jQuery.datepicker._defaults.dateFormat,
+ selectedDate, instance.settings );
+ dates.not( this ).datepicker( "option", option, date );
+ }
+});
diff --git a/plugins/bsc/public/jquery.ui.spinner b/plugins/bsc/public/jquery.ui.spinner
new file mode 160000
index 0000000..bd87900
--- /dev/null
+++ b/plugins/bsc/public/jquery.ui.spinner
@@ -0,0 +1 @@
+Subproject commit bd879003043b4a93b78cbd4a582b6e0650900bcb
diff --git a/plugins/bsc/public/spinner.js b/plugins/bsc/public/spinner.js
new file mode 100644
index 0000000..49ad4b5
--- /dev/null
+++ b/plugins/bsc/public/spinner.js
@@ -0,0 +1,5 @@
+jQuery('#bsc-plugin-contract-spinner').spinner({
+ min: 0,
+ increment: 'fast',
+ mouseWheel: true,
+});
diff --git a/plugins/bsc/public/style.css b/plugins/bsc/public/style.css
index a7bdc16..87da336 100644
--- a/plugins/bsc/public/style.css
+++ b/plugins/bsc/public/style.css
@@ -1,8 +1,27 @@
+@import url(jquery.ui.spinner/ui.spinner.css);
+
.controller-profile_editor a.control-panel-bsc-enterprises {background-image: url(images/manage-bsc-enterprises.png)}
.controller-profile_editor .msie6 a.control-panel-bsc-enterprises {background-image: url(images/manage-bsc-enterprises.gif)}
.controller-profile_editor a.control-panel-transfer-enterprise-ownership {background-image: url(images/transfer-ownership.png)}
+.ui-spinner-up{
+ height: 6.5px !important;
+}
+
+.ui-spinner-down{
+ height: 8.5px !important;
+}
+
+.ui-icon-triangle-1-n {
+ margin-top: -4px !important;
+}
+
+.ui-icon-triangle-1-s {
+ margin-left: -1px !important;
+ margin-top: -3.5px !important;
+}
+
.icon-menu-bsc {
background-image: url(images/manage-bsc-enterprises-icon.png);
}
@@ -10,3 +29,154 @@
#content .token-input-list {
margin-bottom: 30px;
}
+
+#bsc-plugin-sorter {
+ text-align: right;
+ margin: 3px 0px;
+}
+
+#bsc-plugin-sales-table th,
+#bsc-plugin-sales-table td {
+ border: 1px solid #000;
+ border-collapse: collapse;
+ padding: 0px
+}
+
+#content #bsc-plugin-sales-table td .token-input-list{
+ margin-bottom: 0px;
+}
+
+#bsc-plugin-sales-table {
+ border: 1px solid #000;
+ border-collapse: collapse;
+}
+
+#bsc-plugin-sales-table th {
+ background-color: #cdcdcd;
+ padding: 0px 10px;
+}
+
+.alternate-colors tr:nth-child(odd),
+.alternate-colors tr:nth-child(odd):hover td {
+ background-color: #f4f4f4;
+}
+
+.alternate-colors tr:nth-child(even),
+.alternate-colors tr:nth-child(even):hover td {
+ background-color: #fff;
+}
+
+#bsc-plugin-sales-table input.error{
+ background-color: #F8DBDD;
+ border: 1px solid #f5697c;
+ margin-left: 2px;
+}
+
+.bsc-plugin-sales-price {
+ width: 85%;
+}
+
+.bsc-plugin-sales-products-column {
+ width: 70%;
+}
+
+.bsc-plugin-sales-quantity-column {
+ width: 10%;
+ text-align: center;
+}
+
+.bsc-plugin-sales-price-column {
+ width: 18%;
+}
+
+#bsc-plugin-sales-add-new-row {
+ padding: 0px 10px;
+}
+
+#bsc-plugin-manage-contracts-table a {
+ color: #555753;
+}
+
+#bsc-plugin-manage-contracts-table {
+ border:none;
+}
+#bsc-plugin-manage-contracts-table td {
+ padding: 5px 10px;
+}
+
+#bsc-plugin-manage-contracts-table td.links {
+ text-align: right;
+}
+
+#bsc-plugin-contracts-filter {
+ float: left;
+ width: 20%;
+ height: 100%;
+}
+
+
+#bsc-plugin-contracts-results {
+ float: left;
+ width: 80%;
+}
+
+#bsc-plugin-contract-total-string,
+#bsc-plugin-contract-total {
+ text-align: right;
+}
+
+.bsc-fields-table {
+ border: collapse;
+ width: 49%;
+}
+
+.bsc-fields-table th{
+ font-size: 14px;
+ padding: 0px;
+}
+
+.bsc-fields-table td {
+ border: none;
+ padding: 0px;
+}
+
+.bsc-fields-table tr:hover td {
+ background-color: transparent;
+}
+
+.bsc-field-label {
+ font-weight: bold;
+}
+
+.bsc-full-table {
+ margin: 3px 0px;
+}
+
+.bsc-plugin-view-contract {
+ margin-top: 10px;
+}
+
+.bsc-plugin-view-contract td {
+ padding: 2px 10px !important;
+}
+
+.bsc-plugin-total {
+ font-weight: bold;
+}
+
+.bsc-plugin-annotation {
+ background-color: #eeeeec;
+ margin: 10px 0px;
+ padding: 5px 10px;
+ border-radius: 5px;
+}
+
+.bsc-plugin-annotation-title {
+ font-weight: bold;
+ font-size: 15px;
+ margin-bottom: 5px;
+}
+
+.bsc-plugin-annotation-content {
+ font-style: italic;
+}
diff --git a/plugins/bsc/public/validation.js b/plugins/bsc/public/validation.js
new file mode 100644
index 0000000..2060814
--- /dev/null
+++ b/plugins/bsc/public/validation.js
@@ -0,0 +1,4 @@
+jQuery("#bsc-plugin-sales-form").validate({
+ errorPlacement: function(error, element){element.attr('title', error.text())}
+});
+
diff --git a/plugins/bsc/views/bsc_plugin_environment/validate_enterprises.html.erb b/plugins/bsc/views/bsc_plugin_environment/validate_enterprises.html.erb
index fc7953c..57c04f9 100644
--- a/plugins/bsc/views/bsc_plugin_environment/validate_enterprises.html.erb
+++ b/plugins/bsc/views/bsc_plugin_environment/validate_enterprises.html.erb
@@ -1,31 +1,12 @@
<%= _('Validate enterprises') %>
<% form_tag :action => 'save_validations' do %>
- <%= text_field_tag(:q, nil, :id => 'search-enterprises') %>
+ <%= token_input_field_tag(:q, 'search-enterprises', {:action => 'search_enterprise'},
+ { :hint_text => _('Type in a search term for enterprise'),
+ :focus => true }) %>
<% button_bar do %>
<%= submit_button('save', _('Save'))%>
<%= button('cancel', _('Cancel'), {:controller => 'admin_panel'})%>
<% end %>
<% end %>
-
-<%= javascript_include_tag '/plugins/bsc/jquery_tokeninput/src/jquery.tokeninput.js' %>
-<% stylesheet('/plugins/bsc/jquery_tokeninput/styles/token-input.css') %>
-<% search_url = url_for(:action => 'search_enterprise') %>
-
-
diff --git a/plugins/bsc/views/bsc_plugin_myprofile/_contract_form.html.erb b/plugins/bsc/views/bsc_plugin_myprofile/_contract_form.html.erb
new file mode 100644
index 0000000..ba45e67
--- /dev/null
+++ b/plugins/bsc/views/bsc_plugin_myprofile/_contract_form.html.erb
@@ -0,0 +1,83 @@
+<%= error_messages_for :contract %>
+
+<% labelled_form_for :contract, @contract, :html => {:id => 'bsc-plugin-sales-form'} do |f| %>
+ <%= hidden_field_tag :contract_id, @contract.id %>
+ <%= required f.text_field(:client_name) %>
+ <%= labelled_form_field(_('Client type'), f.select(:client_type, BscPlugin::Contract::ClientType.types.map{|type| [BscPlugin::Contract::ClientType.names[type], type]}))%>
+ <%= labelled_form_field(_('Business type'), f.select(:business_type, BscPlugin::Contract::BusinessType.types.map{|type| [BscPlugin::Contract::BusinessType.names[type], type]}))%>
+ <%= f.text_field(:state) %>
+ <%= f.text_field(:city) %>
+ <%= labelled_form_field(_('Status'), f.select(:status, BscPlugin::Contract::Status.types.
+ map { |s| [BscPlugin::Contract::Status.names[s], s] })) %>
+ <%= f.text_field(:number_of_producers, :size => 8, :id => 'bsc-plugin-contract-spinner') %>
+ <%= _('Empreendimentos')+':' %>
+
+ <% search_action = {:action => 'search_contract_enterprises', :profile => profile.identifier} %>
+ <%= token_input_field_tag(:enterprises, 'involved-enterprises', search_action,
+ { :pre_populate => @contract.enterprises_to_token_input,
+ :hint_text => _('Type in serach term for enterprise') }) %>
+
+
+
+ <%= _('Products') %> |
+ <%= _('Quantity') %> |
+ <%= _('Unit price') %> |
+
+
+ <%= _('Total')%> |
+ <%= float_to_currency(@contract.total_price)%> |
+
+
+ <%= link_to(_('Add new product'), {}, :id => 'bsc-plugin-add-new-product', 'data-bsc' => profile.identifier) %> |
+
+
+
+ <%= labelled_form_field( _('Supply period'),
+ text_field_tag('contract[supply_start]', (@contract.supply_start ? @contract.supply_start.strftime("%Y-%m-%d") : nil), :id => 'from', :size => 9) +
+ _(' to ') +
+ text_field_tag('contract[supply_end]', (@contract.supply_end ? @contract.supply_end.strftime("%Y-%m-%d") : nil), :id => 'to', :size => 9) )
+ %>
+
+ <%= f.text_area(:annotations, :rows => 5, :cols => 68) %>
+ <% button_bar do%>
+ <%= submit_button(:save, _('Save'), :cancel => {:action => 'manage_contracts'})%>
+ <% end %>
+<% end %>
+
+<% scripts = %w{/plugins/bsc/jquery.ui.spinner/ui.spinner.js
+ /plugins/bsc/contracts /plugins/bsc/datepicker
+ /plugins/bsc/spinner} %>
+<% scripts.each do |script|%>
+ <%= javascript_include_tag script %>
+<% end %>
+
+
+
+<%= javascript_include_tag '/plugins/bsc/validation' %>
diff --git a/plugins/bsc/views/bsc_plugin_myprofile/edit_contract.html.erb b/plugins/bsc/views/bsc_plugin_myprofile/edit_contract.html.erb
new file mode 100644
index 0000000..eb3d638
--- /dev/null
+++ b/plugins/bsc/views/bsc_plugin_myprofile/edit_contract.html.erb
@@ -0,0 +1,3 @@
+<%= _("New contract") %>
+<%= render :partial => 'contract_form', :locals => {:url => {:action => 'update_contract'}}%>
+
diff --git a/plugins/bsc/views/bsc_plugin_myprofile/manage_associated_enterprises.html.erb b/plugins/bsc/views/bsc_plugin_myprofile/manage_associated_enterprises.html.erb
index 6b8bdf2..9a445bc 100644
--- a/plugins/bsc/views/bsc_plugin_myprofile/manage_associated_enterprises.html.erb
+++ b/plugins/bsc/views/bsc_plugin_myprofile/manage_associated_enterprises.html.erb
@@ -10,7 +10,11 @@
<% end %>
<% form_tag :action => 'save_associations' do %>
- <%= text_field_tag(:q, nil, :id => 'search-enterprises') %>
+ <% search_action = {:action => 'search_enterprise', :profile => profile.identifier} %>
+ <%= token_input_field_tag(:q, 'search-enterprises', search_action,
+ { :pre_populate => profile.enterprises_to_token_input,
+ :hint_text => _('Type in a search term for enterprise'),
+ :focus => true }) %>
<%= button('add', _('Add new enterprise'), {:action => 'create_enterprise'}) %>
@@ -20,24 +24,3 @@
<% end %>
<% end %>
-<%= javascript_include_tag '/plugins/bsc/jquery_tokeninput/src/jquery.tokeninput.js' %>
-<% stylesheet('/plugins/bsc/jquery_tokeninput/styles/token-input.css') %>
-<% search_url = url_for(:action => 'search_enterprise', :profile => profile.identifier) %>
-
diff --git a/plugins/bsc/views/bsc_plugin_myprofile/manage_contracts.html.erb b/plugins/bsc/views/bsc_plugin_myprofile/manage_contracts.html.erb
new file mode 100644
index 0000000..cf74aad
--- /dev/null
+++ b/plugins/bsc/views/bsc_plugin_myprofile/manage_contracts.html.erb
@@ -0,0 +1,49 @@
+<%= _('Manage contracts') %>
+
+<% form_tag({}, {:id => "bsc-plugin-contracts-form"}) do %>
+
+
<%= _('Status') %>
+ <% BscPlugin::Contract::Status.types.each do |status| %>
+ <%= check_box_tag('status[]', status, @status.include?(status.to_s), :id => 'status-checkbox-'+status.to_s) %>
+ <%= content_tag('label', BscPlugin::Contract::Status.names[status], :for => 'status-checkbox-'+status.to_s) %>
+
+ <% end %>
+
+ <%= submit_button(:save, _('Filter')) %>
+
+
+
+
+ <%= labelled_select(_('Sort by')+' ', :sorting, :first, :last, @sorting,
+ [['created_at asc', _('Date(newest first)')], ['created_at desc', _('Date(oldest first)')],
+ ['client_name asc', _('Client name(A-Z)')], ['client_name desc', _('Client name(Z-A)')]],
+ :onchange => "jQuery('#bsc-plugin-contracts-form').submit()") %>
+
+
+ <% if @contracts.blank? %>
+ <%= content_tag('em', _('There are no contracts at all.'))%>
+ <% else %>
+
+ <% @contracts.each do |contract| %>
+
+
+ <%= link_to(content_tag('b', contract.client_name ), :action => 'view_contract', :contract_id => contract.id) %>
+ <%= content_tag('i', show_date(contract.created_at)) %>
+ |
+
+ <%= link_to(_('Edit'), :action => 'edit_contract', :contract_id => contract.id)%>
+ <%= link_to(_('Remove'), {:action => 'destroy_contract', :contract_id => contract.id}, :confirm => _('Are you sure?'))%>
+ |
+
+ <% end %>
+
+ <%= pagination_links @contracts %>
+ <% end %>
+
+ <% button_bar do %>
+ <%= button(:back, _('Go back'), :controller => 'profile_editor') %>
+ <%= button(:new, _('Create new contract'), :action => 'new_contract')%>
+ <% end %>
+
+<% end %>
+
diff --git a/plugins/bsc/views/bsc_plugin_myprofile/new_contract.html.erb b/plugins/bsc/views/bsc_plugin_myprofile/new_contract.html.erb
new file mode 100644
index 0000000..988be28
--- /dev/null
+++ b/plugins/bsc/views/bsc_plugin_myprofile/new_contract.html.erb
@@ -0,0 +1,2 @@
+<%= _("New contract") %>
+<%= render :partial => 'contract_form.html.erb', :locals => {:url => {:action => 'create_contract'}}%>
diff --git a/plugins/bsc/views/bsc_plugin_myprofile/transfer_ownership.html.erb b/plugins/bsc/views/bsc_plugin_myprofile/transfer_ownership.html.erb
index 9312f99..87ed39f 100644
--- a/plugins/bsc/views/bsc_plugin_myprofile/transfer_ownership.html.erb
+++ b/plugins/bsc/views/bsc_plugin_myprofile/transfer_ownership.html.erb
@@ -13,10 +13,16 @@
<% end %>
+
<% form_tag do %>
<% @roles.each do |role|%>
<%= content_tag('b', _('Administrator:')) %>
- <%= text_field_tag('q_'+role.key, nil, :id => 'search_'+role.key) %>
+ <% search_action = {:controller => 'profile_members', :action => 'search_user', :role => role.id, :profile => profile.identifier} %>
+ <%= token_input_field_tag('q_'+role.key, 'search_'+role.key, search_action,
+ { :hint_text => _('Type in a search term for the new administrator'),
+ :focus => true,
+ :token_limit => 1}) %>
+
<% end %>
<% button_bar do %>
@@ -24,31 +30,3 @@
<%= button('cancel', _('Cancel'), {:controller => 'profile_editor'})%>
<% end %>
<% end %>
-
-<%= javascript_include_tag '/plugins/bsc/jquery_tokeninput/src/jquery.tokeninput.js' %>
-<% stylesheet('/plugins/bsc/jquery_tokeninput/styles/token-input.css') %>
-
-<% @roles.each do |role| %>
- <% search_url = url_for(:controller => 'profile_members', :action => 'search_user', :role => role.id, :profile => profile.identifier) %>
-
-<% end %>
-
-
diff --git a/plugins/bsc/views/bsc_plugin_myprofile/view_contract.html.erb b/plugins/bsc/views/bsc_plugin_myprofile/view_contract.html.erb
new file mode 100644
index 0000000..4891376
--- /dev/null
+++ b/plugins/bsc/views/bsc_plugin_myprofile/view_contract.html.erb
@@ -0,0 +1,55 @@
+<%= @contract.client_name %>
+
+
+
+ <%= _('Basic information') %> |
+
+ <%= display_text_field(_('Client type'), BscPlugin::Contract::ClientType.names[@contract.client_type]) %>
+ <%= display_text_field(_('Business type'), BscPlugin::Contract::BusinessType.names[@contract.business_type]) %>
+ <%= display_text_field(_('State'), @contract.state) %>
+ <%= display_text_field(_('City'), @contract.city) %>
+ <%= display_text_field(_('Status'), BscPlugin::Contract::Status.names[@contract.status]) %>
+ <%= display_text_field(_('Number of producers'), @contract.number_of_producers) %>
+ <%= display_text_field(_('Supply period'), show_period(@contract.supply_start, @contract.supply_end, true)) %>
+
+
+
+
+ <%= _('Enterprises') %> |
+
+ <%= display_list_field(@contract.enterprises.map {|enterprise| link_to(enterprise.short_name(60), enterprise.url)}) %>
+
+
+<% if !@contract.sales.blank?%>
+
+
+ <%= _('Product') %> |
+ <%= _('Quantity') %> |
+ <%= _('Unit price') %> |
+
+ <% @contract.sales.each do |sale| %>
+
+ <%= short_text(product_display_name(Product.find(sale.product_id)), 110) %> |
+ <%= sale.quantity %> |
+ <%= float_to_currency(sale.price) %> |
+
+ <% end %>
+
+ <%= _('Total')%> |
+ <%= float_to_currency(@contract.total_price) %> |
+
+
+<% end %>
+
+
+
+<% if !@contract.annotations.blank? %>
+
+
<%= _("Annotations") %>
+
<%= @contract.annotations %>
+
+<% end %>
+
+<% button_bar do %>
+ <%= button(:back, _('Go back'), :action => 'manage_contracts') %>
+<% end %>
--
libgit2 0.21.2