Merge branch 'b-3.6.1' of ../kivitendo-erp_20220811
[kivitendo-erp.git] / templates / webpages / csv_import / form.html
index c40c563..568324e 100644 (file)
@@ -6,11 +6,16 @@
 
  [%- INCLUDE 'common/flash.html' %]
 
- <form method="post" action="controller.pl" enctype="multipart/form-data">
+ <form method="post" action="controller.pl" enctype="multipart/form-data" id="form">
   [% L.hidden_tag('form_sent', '1') %]
   [% L.hidden_tag('action', 'CsvImport/dispatch') %]
   [% L.hidden_tag('profile.type', SELF.profile.type) %]
+  [% L.hidden_tag('tmp_profile_id', SELF.profile.id) %]
 
+ [%- IF SELF.profile.get('dont_edit_profile') %]
+  [% L.hidden_tag('force_profile', 1) %]
+  [% L.hidden_tag('profile.id', SELF.profile.id) %]
+ [%- ELSE %][%# IF SELF.profile.get('dont_edit_profile') %]
   <h2>[%- LxERP.t8('Import profiles') %]</h2>
 
   <table>
@@ -19,7 +24,7 @@
      <th align="right">[%- LxERP.t8('Current profile') %]:</th>
      <td>[%- HTML.escape(SELF.profile.name) %]</td>
     </tr>
-   [%- END %]
+   [%- END %][%# IF SELF.profile.id %]
 
    [%- IF SELF.all_profiles.size %]
     <tr>
@@ -32,7 +37,7 @@
       [% L.submit_tag('action_destroy', LxERP.t8('Delete profile'), confirm => LxERP.t8('Do you really want to delete this object?')) %]
      </td>
     </tr>
-   [%- END %]
+   [%- END %][%# IF SELF.all_profiles.size %]
 
    <tr>
     <th align="right" valign="top">[%- LxERP.t8('Save settings as') %]:</th>
@@ -61,9 +66,9 @@
        <tr class="listheading">
          [%- FOREACH p = SELF.worker.profile %]
            <th>[%- p.row_ident %]</th>
-         [%- END %]
+         [%- END %][%# FOREACH SELF.worker.profile %]
        </tr>
-       <tr class="listrow[% loop.count % 2 %]">
+       <tr style="vertical-align:top">
          [%- FOREACH p = SELF.worker.profile %]
            [% SET ri = p.row_ident %]
          <td>
                <td>[%- HTML.escape(row.name) %]</td>
                <td>[%- HTML.escape(row.description) %]</td>
              </tr>
-             [%- END %]
+             [%- END %][%# FOREACH SELF.displayable_columns.$ri %]
            </table>
          </td>
-         [%- END %]
+         [%- END %][%# FOREACH SELF.worker.profile %]
        </tr>
      </table>
-   [%- ELSE %]
+   [%- ELSE %][%# IF SELF.worker.is_multiplexed %]
      <table>
        <tr class="listheading">
          <th>[%- LxERP.t8('Column name') %]</th>
          <td>[%- HTML.escape(row.name) %]</td>
          <td>[%- HTML.escape(row.description) %]</td>
        </tr>
-       [%- END %]
+       [%- END %][%# FOREACH SELF.displayable_columns %]
      </table>
-   [%- END %]
+   [%- END %][%# SELF.worker.is_multiplexed %]
 
 [%- IF SELF.type == 'contacts' %]
    <p>
     [%- LxERP.t8("You can update existing contacts by providing the 'cp_id' column with their database IDs. Otherwise: ") %]
-    [%- LxERP.t8('At least one of the columns #1, customer, customernumber, vendor, vendornumber (depending on the target table) is required for matching the entry to an existing customer or vendor.', 'cp_cv_id') %]
+    [%- LxERP.t8('At least one of the columns #1, customer, customernumber, customer_gln, vendor, vendornumber, vendor_gln (depending on the target table) is required for matching the entry to an existing customer or vendor.', 'cp_cv_id') %]
    </p>
 
 [%- ELSIF SELF.type == 'addresses' %]
    <p>
-    [%- LxERP.t8('At least one of the columns #1, customer, customernumber, vendor, vendornumber (depending on the target table) is required for matching the entry to an existing customer or vendor.', 'trans_id') %]
+    [%- LxERP.t8('At least one of the columns #1, customer, customernumber, customer_gln, vendor, vendornumber, vendor_gln (depending on the target table) is required for matching the entry to an existing customer or vendor.', 'trans_id') %]
    </p>
 
 [%- ELSIF SELF.type == 'parts' %]
    </p>
    <p>
     [3]:
-    [% LxERP.t8("If the article type is set to 'mixed' then a column called 'type' must be present.") %]
+    [% LxERP.t8("If the article type is set to 'mixed' then a column called 'part_type' or called 'pclass' must be present.") %]
     [% LxERP.t8("Type can be either 'part', 'service' or 'assembly'.") %]
-    [% LxERP.t8("Assemblies can not be imported (yet). But the type column is used for sanity checks on price updates in order to prevent that articles with the wrong type will be updated.") %]
+    [%- LxERP.t8("If column 'pclass' is present the article type is then irrelevant or used as default ") %]
+    [% LxERP.t8("The 'pclass' column has the same abbreviation like a part export. The first letter is for the type Part,Assembly or Service, the second(and third) for Part Classification") %]
    </p>
 
 [%- ELSIF SELF.type == 'inventories' %]
     [%- LxERP.t8('One of the columns "qty" or "target_qty" must be given. If "target_qty" is given, the quantity to transfer for each transfer will be calculate, so that the quantity for this part, warehouse and bin will result in the given "target_qty" after each transfer.') %]
    </p>
 
-[%- ELSIF SELF.type == 'orders' %]
+[%- ELSIF SELF.type == 'orders' OR SELF.type == 'delivery_orders' OR SELF.type == 'ar_transactions' %]
    <p>
     [1]:
     [% LxERP.t8('The column "datatype" must be present and must be at the same position / column in each data set. The values must be the row names (see settings) for order and item data respectively.') %]
    </p>
-   <p>
-    [2]:
-    [%- LxERP.t8('Amount and net amount are calculated by kivitendo. "verify_amount" and "verify_netamount" can be used for sanity checks.') %]<br>
-    [%- LxERP.t8('If amounts differ more than "Maximal amount difference" (see settings), this item is marked as invalid.') %]<br>
-   </p>
-[%- END %]
-
-   <p>
-    [%- L.submit_tag('action_download_sample', LxERP.t8('Download sample file')) %]
-   </p>
+   [%- IF SELF.type == 'orders' OR SELF.type == 'ar_transactions' %]
+    <p>
+     [2]:
+     [%- LxERP.t8('Amount and net amount are calculated by kivitendo. "verify_amount" and "verify_netamount" can be used for sanity checks.') %]<br>
+     [%- LxERP.t8('If amounts differ more than "Maximal amount difference" (see settings), this item is marked as invalid.') %]<br>
+    </p>
+   [%- END %]
+[%- END %][%# IF SELF.type == … %]
+  </div>
 
+  <div>
+    <p>
+      [%- L.submit_tag('action_download_sample', LxERP.t8('Download sample file')) %]
+    </p>
   </div>
 
   <hr>
    <tr>
     <th align="right">[%- LxERP.t8('Number Format') %]:</th>
     <td colspan="10">
-     [% L.select_tag('settings.numberformat', ['1.000,00', '1000,00', '1,000.00', '1000.00'], default = SELF.profile.get('numberformat'), style = 'width: 300px') %]
+     [% L.select_tag('settings.numberformat', ['1.000,00', '1000,00', '1,000.00', '1000.00', "1'000.00"], default = SELF.profile.get('numberformat'), style = 'width: 300px') %]
+    </td>
+   </tr>
+
+   <tr>
+    <th align="right">[%- LxERP.t8('Date Format') %]:</th>
+    <td colspan="10">
+     [% L.select_tag('settings.dateformat', ['dd.mm.yyyy', 'yyyy-mm-dd', 'dd/mm/yyyy', 'mm/dd/yyyy' ], default = SELF.profile.get('dateformat'), style = 'width: 300px') %]
     </td>
    </tr>
 
       [% IF SELF.sep_char == entry.first %] [% SET custom_sep_char = '' %] [%- END %]
       [% L.radio_button_tag('sep_char', value => entry.first, label => entry.last, checked => SELF.sep_char == entry.first) %]
      </td>
-    [%- END %]
+    [%- END %][%# FOREACH SELF.all_sep_chars %]
 
     <td>
      [% L.radio_button_tag('sep_char', value => 'custom', checked => custom_sep_char != '') %]
       [% IF SELF.quote_char == entry.first %] [% SET custom_quote_char = '' %] [%- END %]
       [% L.radio_button_tag('quote_char', value => entry.first, label => entry.last, checked => SELF.quote_char == entry.first) %]
      </td>
-    [%- END %]
+    [%- END %][%# FOREACH SELF.all_quote_chars %]
 
     <td>
      [% L.radio_button_tag('quote_char', value => 'custom', checked => custom_quote_char != '') %]
       [% IF SELF.escape_char == entry.first %] [% SET custom_escape_char = '' %] [%- END %]
       [% L.radio_button_tag('escape_char', value => entry.first, label => entry.last, checked => SELF.escape_char == entry.first) %]
      </td>
-    [%- END %]
+    [%- END %][%# FOREACH SELF.all_escape_chars %]
 
     <td>
      [% L.radio_button_tag('escape_char', value => 'custom', checked => custom_escape_char != '') %]
          [% FOREACH key = duplicate_fields.keys %]
            <input type="checkbox" name="settings.duplicates_[% key | html %]" id="settings.duplicates_[% key | html %]" value="1"[% IF ( SELF.profile.get('duplicates_'_ key) || (duplicate_fields.$key.default && !FORM.form_sent ) ) %] checked="checked"[% END %]>
            <label for="settings.duplicates_[% key | html %]">[% duplicate_fields.$key.label | html %]</label>
-         [% END %]
+         [% END %][%# FOREACH duplicate_fields.keys %]
        </td>
      </tr>
 
          [% L.select_tag('settings.duplicates', opts, default = SELF.profile.get('duplicates'), style = 'width: 300px') %]
        </td>
      </tr>
-   [% END %]
+   [% END %][%# IF duplicate_fields.size %]
 
 [%- IF SELF.type == 'parts' %]
  [%- INCLUDE 'csv_import/_form_parts.html' %]
  [%- INCLUDE 'csv_import/_form_inventories.html' %]
 [%- ELSIF SELF.type == 'orders' %]
  [%- INCLUDE 'csv_import/_form_orders.html' %]
+[%- ELSIF SELF.type == 'delivery_orders' %]
+ [%- INCLUDE 'csv_import/_form_delivery_orders.html' %]
+[%- ELSIF SELF.type == 'ar_transactions' %]
+ [%- INCLUDE 'csv_import/_form_artransactions.html' %]
 [%- ELSIF SELF.type == 'bank_transactions' %]
  [%- INCLUDE 'csv_import/_form_banktransactions.html' %]
 [%- END %]
    <tr>
     <th align="right">[%- LxERP.t8('Preview Mode') %]:</th>
     <td colspan="10">
-      [% L.radio_button_tag('settings.full_preview', value=2, checked=SELF.profile.get('full_preview')==2, label=LxERP.t8('Full Preview')) %]
-      [% L.radio_button_tag('settings.full_preview', value=1, checked=SELF.profile.get('full_preview')==1, label=LxERP.t8('Only Warnings and Errors')) %]
-      [% L.radio_button_tag('settings.full_preview', value=0, checked=!SELF.profile.get('full_preview'),   label=LxERP.t8('First 20 Lines')) %]
+      [% L.radio_button_tag('settings.full_preview', value=0, checked=!SELF.profile.get('full_preview'),   label=LxERP.t8('Full Preview')) %]
+      [% L.radio_button_tag('settings.full_preview', value=1, checked=SELF.profile.get('full_preview')==1, label=LxERP.t8('Only Lines with Notes or Errors')) %]
+      [% L.radio_button_tag('settings.full_preview', value=2, checked=SELF.profile.get('full_preview')==2, label=LxERP.t8('First 20 Lines')) %]
     </td>
    </tr>
 
      <th align="right">[%- LxERP.t8('Existing file on server') %]:</th>
      <td colspan="10">[%- LxERP.t8('Uploaded on #1, size #2 kB', SELF.file.displayable_mtime, LxERP.format_amount(SELF.file.size / 1024, 2)) %]</td>
     </tr>
-   [%- END %]
+   [%- END %][%# IF SELF.file.exists %]
 
   </table>
 
   </div>
   <hr>
 
-  [% L.submit_tag('action_test', LxERP.t8('Test and preview')) %]
-  [% L.submit_tag('action_import', LxERP.t8('Import'), style='display:none') %]
+[%- UNLESS SELF.worker.is_multiplexed %]
+  <h2>[% 'Mappings (csv_import)' | $T8 %]</h2>
+
+  <div class="mappings_toggle"[% UNLESS SELF.deferred || SELF.import_status %] style="display:none"[% END %]>
+   <a href="#" onClick="javascript:$('.mappings_toggle').toggle()">[% LxERP.t8("Show mappings (csv_import)") %]</a>
+  </div>
+  <div class="mappings_toggle"[% IF SELF.deferred || SELF.import_status %] style="display:none"[% END %]>
+   <p><a href="#" onClick="javascript:$('.mappings_toggle').toggle()">[% LxERP.t8("Hide mappings (csv_import)") %]</a></p>
+
+    <p>[% 'These mappings can be used to map heading from non standard csv files to known columns. These will also be saved in profiles, so you can save profiles for every source of formats.' | $T8 %]</p>
+
+  <table id="csv_import_mappings">
+   <tr class=listheading>
+    <th></th>
+    <th>[% 'Text in CSV File' | $T8 %]</th>
+    <th>[% 'Known Column' | $T8 %]</th>
+   </tr>
+   <tr id='mapping_empty' style='display:none'>
+    <td colspan=3>[% 'There is nothing here yet (csv_import)' | $T8 %]</td>
+   </tr>
+[%- FOREACH row = SELF.mappings %]
+   [% PROCESS 'csv_import/_mapping_item.html', item=row IF row.from %]
+[%- END %][%# FOREACH SELF.mappings %]
+   [% PROCESS 'csv_import/_mapping_item.html', item={} %]
+  </table>
+
+  <input type=button id='add_empty_mapping_line' value='[% 'Add empty line (csv_import)' | $T8 %]'>
+  <input type=button id='add_mapping_from_upload' value='[% 'Add headers from last uploaded file (csv_import)' | $T8 %]'>
 
+  </div>
+  <hr>
+[%- END %][%# UNLESS SELF.worker.is_multiplexed %]
+[%- END %][%# IF SELF.profile.get('dont_edit_profile') %]
  </form>
 
  <div id='results'>
  [%- IF SELF.deferred %]
    [%- PROCESS 'csv_import/_deferred_results.html' %]
- [%- ELSIF SELF.import_status %]
-   [%- PROCESS 'csv_import/_results.html' %]
- [%- END %]
+ [%- END %][%# IF SELF.deferred %]
  </div>
 
 
           return true;
         alert('[% LxERP.t8('Please enter a profile name.') %]');
         return false;
-      })
+      });
+      $('#add_empty_mapping_line').click(function(){
+        $.get('controller.pl', { action: 'CsvImport/add_empty_mapping_line', 'profile.type': $('#profile_type').val() }, kivi.eval_json_result);
+      });
+      $('#add_mapping_from_upload').click(function(){
+        $.get('controller.pl?action_add_mapping_from_upload=1', $('form').serialize() , kivi.eval_json_result);
+      });
+      $('#csv_import_mappings').on('click', '.remove_line', function(){ $(this).closest('tr').remove(); if (1==$('#csv_import_mappings tr:visible').length) $('#mapping_empty').show() });
     });
     -->
  </script>