cb07c038355cdb72e6a399907e090432df5dd2b3
[kivitendo-erp.git] / templates / webpages / csv_import / form.html
1 [%- USE HTML %]
2 [%- USE LxERP %]
3 [%- USE L %]
4 [%- USE T8 %]
5  <h1>[% FORM.title %]</h1>
6
7  [%- INCLUDE 'common/flash.html' %]
8
9  <form method="post" action="controller.pl" enctype="multipart/form-data" id="form">
10   [% L.hidden_tag('form_sent', '1') %]
11   [% L.hidden_tag('action', 'CsvImport/dispatch') %]
12   [% L.hidden_tag('profile.type', SELF.profile.type) %]
13   [% L.hidden_tag('tmp_profile_id', SELF.profile.id) %]
14
15  [%- IF SELF.profile.get('dont_edit_profile') %]
16   [% L.hidden_tag('force_profile', 1) %]
17   [% L.hidden_tag('profile.id', SELF.profile.id) %]
18  [%- ELSE %][%# IF SELF.profile.get('dont_edit_profile') %]
19   <h2>[%- LxERP.t8('Import profiles') %]</h2>
20
21   <table>
22    [%- IF SELF.profile.id %]
23     <tr>
24      <th align="right">[%- LxERP.t8('Current profile') %]:</th>
25      <td>[%- HTML.escape(SELF.profile.name) %]</td>
26     </tr>
27    [%- END %][%# IF SELF.profile.id %]
28
29    [%- IF SELF.all_profiles.size %]
30     <tr>
31      <th align="right">[%- LxERP.t8('Existing profiles') %]:</th>
32      <td>
33       [% L.select_tag('profile.id', SELF.all_profiles, title_key = 'name', default = SELF.profile.id, style = 'width: 300px') %]
34      </td>
35      <td>
36       [% L.submit_tag('action_new', LxERP.t8('Load profile')) %]
37       [% L.submit_tag('action_destroy', LxERP.t8('Delete profile'), confirm => LxERP.t8('Do you really want to delete this object?')) %]
38      </td>
39     </tr>
40    [%- END %][%# IF SELF.all_profiles.size %]
41
42    <tr>
43     <th align="right" valign="top">[%- LxERP.t8('Save settings as') %]:</th>
44     <td valign="top">
45      [% L.input_tag('profile.name', '', style => 'width: 300px') %]
46      <br>
47      [% L.checkbox_tag('profile.is_default', label => LxERP.t8('Make default profile')) %]
48     </td>
49     <td valign="top">[% L.submit_tag('action_save', LxERP.t8('Save profile')) %]</td>
50    </tr>
51   </table>
52
53   <hr>
54
55   <h2>[%- LxERP.t8('Help on column names') %]</h2>
56
57   <div class="help_toggle">
58    <a href="#" onClick="javascript:$('.help_toggle').toggle()">[% LxERP.t8("Show help text") %]</a>
59   </div>
60
61   <div class="help_toggle" style="display:none">
62    <p><a href="#" onClick="javascript:$('.help_toggle').toggle()">[% LxERP.t8("Hide help text") %]</a></p>
63
64    [%- IF SELF.worker.is_multiplexed %]
65      <table>
66        <tr class="listheading">
67          [%- FOREACH p = SELF.worker.profile %]
68            <th>[%- p.row_ident %]</th>
69          [%- END %][%# FOREACH SELF.worker.profile %]
70        </tr>
71        <tr style="vertical-align:top">
72          [%- FOREACH p = SELF.worker.profile %]
73            [% SET ri = p.row_ident %]
74          <td>
75            <table>
76              <tr class="listheading">
77                <th>[%- LxERP.t8('Column name') %]</th>
78                <th>[%- LxERP.t8('Meaning') %]</th>
79              </tr>
80
81              [%- FOREACH row = SELF.displayable_columns.$ri %]
82              <tr class="listrow[% loop.count % 2 %]">
83                <td>[%- HTML.escape(row.name) %]</td>
84                <td>[%- HTML.escape(row.description) %]</td>
85              </tr>
86              [%- END %][%# FOREACH SELF.displayable_columns.$ri %]
87            </table>
88          </td>
89          [%- END %][%# FOREACH SELF.worker.profile %]
90        </tr>
91      </table>
92    [%- ELSE %][%# IF SELF.worker.is_multiplexed %]
93      <table>
94        <tr class="listheading">
95          <th>[%- LxERP.t8('Column name') %]</th>
96          <th>[%- LxERP.t8('Meaning') %]</th>
97        </tr>
98
99        [%- FOREACH row = SELF.displayable_columns %]
100        <tr class="listrow[% loop.count % 2 %]">
101          <td>[%- HTML.escape(row.name) %]</td>
102          <td>[%- HTML.escape(row.description) %]</td>
103        </tr>
104        [%- END %][%# FOREACH SELF.displayable_columns %]
105      </table>
106    [%- END %][%# SELF.worker.is_multiplexed %]
107
108 [%- IF SELF.type == 'contacts' %]
109    <p>
110     [%- LxERP.t8("You can update existing contacts by providing the 'cp_id' column with their database IDs. Otherwise: ") %]
111     [%- 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') %]
112    </p>
113
114 [%- ELSIF SELF.type == 'addresses' %]
115    <p>
116     [%- 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') %]
117    </p>
118
119 [%- ELSIF SELF.type == 'parts' %]
120    <p>
121     [1]:
122     [% LxERP.t8('The three columns "make_X", "model_X" and "lastcost_X" with the same number "X" are used to import vendor part numbers and vendor prices.') %]
123     [% LxERP.t8('The column triplets can occur multiple times with different numbers "X" each time (e.g. "make_1", "model_1", "lastcost_1", "make_2", "model_2", "lastcost_2", "make_3", "model_3", "lastcost_3" etc).') %]
124     [% LxERP.t8('The items are imported accoring do their number "X" regardless of the column order inside the file.') %]
125     [% LxERP.t8('The column "make_X" can contain either a vendor\'s database ID, a vendor number or a vendor\'s name.') %]
126    </p>
127     <p>
128     [2]:
129     [% LxERP.t8('Onhand only sets the quantity in master data, not in inventory. This is only a legacy info field and will be overwritten as soon as a inventory transfer happens.') %]
130    </p>
131    <p>
132     [3]:
133     [% LxERP.t8("If the article type is set to 'mixed' then a column called 'part_type' or called 'pclass' must be present.") %]
134     [% LxERP.t8("Type can be either 'part', 'service' or 'assembly'.") %]
135     [%- LxERP.t8("If column 'pclass' is present the article type is then irrelevant or used as default ") %]
136     [% 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") %]
137    </p>
138
139 [%- ELSIF SELF.type == 'inventories' %]
140    <p>
141     [%- 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.') %]
142    </p>
143
144 [%- ELSIF SELF.type == 'orders' OR SELF.type == 'ar_transactions' %]
145    <p>
146     [1]:
147     [% 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.') %]
148    </p>
149    <p>
150     [2]:
151     [%- LxERP.t8('Amount and net amount are calculated by kivitendo. "verify_amount" and "verify_netamount" can be used for sanity checks.') %]<br>
152     [%- LxERP.t8('If amounts differ more than "Maximal amount difference" (see settings), this item is marked as invalid.') %]<br>
153    </p>
154 [%- END %][%# IF SELF.type == … %]
155
156    <p>
157     [%- L.submit_tag('action_download_sample', LxERP.t8('Download sample file')) %]
158    </p>
159
160   </div>
161
162   <hr>
163
164   <h2>[%- LxERP.t8('Settings') %]</h2>
165
166   <div class="settings_toggle"[% UNLESS SELF.deferred || SELF.import_status %] style="display:none"[% END %]>
167    <a href="#" onClick="javascript:$('.settings_toggle').toggle()">[% LxERP.t8("Show settings") %]</a>
168   </div>
169
170   <div class="settings_toggle"[% IF SELF.deferred || SELF.import_status %] style="display:none"[% END %]>
171    <p><a href="#" onClick="javascript:$('.settings_toggle').toggle()">[% LxERP.t8("Hide settings") %]</a></p>
172
173   <table>
174    <tr>
175     <th align="right">[%- LxERP.t8('Number Format') %]:</th>
176     <td colspan="10">
177      [% 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') %]
178     </td>
179    </tr>
180
181    <tr>
182     <th align="right">[%- LxERP.t8('Charset') %]:</th>
183     <td colspan="10">[% L.select_tag('settings.charset', SELF.all_charsets, default = SELF.profile.get('charset'), style = 'width: 300px') %]</td>
184    </tr>
185
186    <tr>
187     <th align="right">[%- LxERP.t8('Separator') %]:</th>
188     [% SET custom_sep_char = SELF.sep_char %]
189     [% FOREACH entry = SELF.all_sep_chars %]
190      <td>
191       [% IF SELF.sep_char == entry.first %] [% SET custom_sep_char = '' %] [%- END %]
192       [% L.radio_button_tag('sep_char', value => entry.first, label => entry.last, checked => SELF.sep_char == entry.first) %]
193      </td>
194     [%- END %][%# FOREACH SELF.all_sep_chars %]
195
196     <td>
197      [% L.radio_button_tag('sep_char', value => 'custom', checked => custom_sep_char != '') %]
198      [% L.input_tag('custom_sep_char', custom_sep_char, size => 3, maxlength => 1) %]
199     </td>
200    </tr>
201
202    <tr>
203     <th align="right">[%- LxERP.t8('Quote character') %]:</th>
204     [% SET custom_quote_char = SELF.quote_char %]
205     [% FOREACH entry = SELF.all_quote_chars %]
206      <td>
207       [% IF SELF.quote_char == entry.first %] [% SET custom_quote_char = '' %] [%- END %]
208       [% L.radio_button_tag('quote_char', value => entry.first, label => entry.last, checked => SELF.quote_char == entry.first) %]
209      </td>
210     [%- END %][%# FOREACH SELF.all_quote_chars %]
211
212     <td>
213      [% L.radio_button_tag('quote_char', value => 'custom', checked => custom_quote_char != '') %]
214      [% L.input_tag('custom_quote_char', custom_quote_char, size => 3, maxlength => 1) %]
215     </td>
216    </tr>
217
218    <tr>
219     <th align="right">[%- LxERP.t8('Escape character') %]:</th>
220     [% SET custom_escape_char = SELF.escape_char %]
221     [% FOREACH entry = SELF.all_escape_chars %]
222      <td>
223       [% IF SELF.escape_char == entry.first %] [% SET custom_escape_char = '' %] [%- END %]
224       [% L.radio_button_tag('escape_char', value => entry.first, label => entry.last, checked => SELF.escape_char == entry.first) %]
225      </td>
226     [%- END %][%# FOREACH SELF.all_escape_chars %]
227
228     <td>
229      [% L.radio_button_tag('escape_char', value => 'custom', checked => custom_escape_char != '') %]
230      [% L.input_tag('custom_escape_char', custom_escape_char, size => 3, maxlength => 1) %]
231     </td>
232    </tr>
233
234    [% duplicate_fields = SELF.worker.get_duplicate_check_fields() %]
235    [% IF ( duplicate_fields.size ) %]
236      <tr>
237        <th align="right">[%- LxERP.t8('Check for duplicates') %]:</th>
238
239        <td colspan=10>
240          [% FOREACH key = duplicate_fields.keys %]
241            <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 %]>
242            <label for="settings.duplicates_[% key | html %]">[% duplicate_fields.$key.label | html %]</label>
243          [% END %][%# FOREACH duplicate_fields.keys %]
244        </td>
245      </tr>
246
247      <tr>
248        <th align="right"></th>
249
250        <td colspan=10>
251          [% opts = [ [ 'no_check',  LxERP.t8('Do not check for duplicates') ],
252                      [ 'check_csv', LxERP.t8('Discard duplicate entries in CSV file') ],
253                      [ 'check_db',  LxERP.t8('Discard entries with duplicates in database or CSV file') ] ] %]
254          [% L.select_tag('settings.duplicates', opts, default = SELF.profile.get('duplicates'), style = 'width: 300px') %]
255        </td>
256      </tr>
257    [% END %][%# IF duplicate_fields.size %]
258
259 [%- IF SELF.type == 'parts' %]
260  [%- INCLUDE 'csv_import/_form_parts.html' %]
261 [%- ELSIF SELF.type == 'customers_vendors' %]
262  [%- INCLUDE 'csv_import/_form_customers_vendors.html' %]
263 [%- ELSIF SELF.type == 'contacts' %]
264  [%- INCLUDE 'csv_import/_form_contacts.html' %]
265 [%- ELSIF SELF.type == 'inventories' %]
266  [%- INCLUDE 'csv_import/_form_inventories.html' %]
267 [%- ELSIF SELF.type == 'orders' %]
268  [%- INCLUDE 'csv_import/_form_orders.html' %]
269 [%- ELSIF SELF.type == 'ar_transactions' %]
270  [%- INCLUDE 'csv_import/_form_artransactions.html' %]
271 [%- ELSIF SELF.type == 'bank_transactions' %]
272  [%- INCLUDE 'csv_import/_form_banktransactions.html' %]
273 [%- END %]
274
275    <tr>
276     <th align="right">[%- LxERP.t8('Preview Mode') %]:</th>
277     <td colspan="10">
278       [% L.radio_button_tag('settings.full_preview', value=0, checked=!SELF.profile.get('full_preview'),   label=LxERP.t8('Full Preview')) %]
279       [% 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')) %]
280       [% L.radio_button_tag('settings.full_preview', value=2, checked=SELF.profile.get('full_preview')==2, label=LxERP.t8('First 20 Lines')) %]
281     </td>
282    </tr>
283
284    <tr>
285     <th align="right">[%- LxERP.t8('Import file') %]:</th>
286     <td colspan="10">[% L.input_tag('file', '', type => 'file', accept => '*') %]</td>
287    </tr>
288
289    [%- IF SELF.file.exists %]
290     <tr>
291      <th align="right">[%- LxERP.t8('Existing file on server') %]:</th>
292      <td colspan="10">[%- LxERP.t8('Uploaded on #1, size #2 kB', SELF.file.displayable_mtime, LxERP.format_amount(SELF.file.size / 1024, 2)) %]</td>
293     </tr>
294    [%- END %][%# IF SELF.file.exists %]
295
296   </table>
297
298   </div>
299   <hr>
300
301 [%- UNLESS SELF.worker.is_multiplexed %]
302   <h2>[% 'Mappings (csv_import)' | $T8 %]</h2>
303
304   <div class="mappings_toggle"[% UNLESS SELF.deferred || SELF.import_status %] style="display:none"[% END %]>
305    <a href="#" onClick="javascript:$('.mappings_toggle').toggle()">[% LxERP.t8("Show mappings (csv_import)") %]</a>
306   </div>
307   <div class="mappings_toggle"[% IF SELF.deferred || SELF.import_status %] style="display:none"[% END %]>
308    <p><a href="#" onClick="javascript:$('.mappings_toggle').toggle()">[% LxERP.t8("Hide mappings (csv_import)") %]</a></p>
309
310     <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>
311
312   <table id="csv_import_mappings">
313    <tr class=listheading>
314     <th></th>
315     <th>[% 'Text in CSV File' | $T8 %]</th>
316     <th>[% 'Known Column' | $T8 %]</th>
317    </tr>
318    <tr id='mapping_empty' style='display:none'>
319     <td colspan=3>[% 'There is nothing here yet (csv_import)' | $T8 %]</td>
320    </tr>
321 [%- FOREACH row = SELF.mappings %]
322    [% PROCESS 'csv_import/_mapping_item.html', item=row IF row.from %]
323 [%- END %][%# FOREACH SELF.mappings %]
324    [% PROCESS 'csv_import/_mapping_item.html', item={} %]
325   </table>
326
327   <input type=button id='add_empty_mapping_line' value='[% 'Add empty line (csv_import)' | $T8 %]'>
328   <input type=button id='add_mapping_from_upload' value='[% 'Add headers from last uploaded file (csv_import)' | $T8 %]'>
329
330   </div>
331   <hr>
332 [%- END %][%# UNLESS SELF.worker.is_multiplexed %]
333 [%- END %][%# IF SELF.profile.get('dont_edit_profile') %]
334  </form>
335
336  <div id='results'>
337  [%- IF SELF.deferred %]
338    [%- PROCESS 'csv_import/_deferred_results.html' %]
339  [%- END %][%# IF SELF.deferred %]
340  </div>
341
342
343  <script type="text/javascript">
344   <!--
345     $(document).ready(function() {
346       $('#action_save').click(function() {
347         if ($('#profile_name').val() != '')
348           return true;
349         alert('[% LxERP.t8('Please enter a profile name.') %]');
350         return false;
351       });
352       $('#add_empty_mapping_line').click(function(){
353         $.get('controller.pl', { action: 'CsvImport/add_empty_mapping_line', 'profile.type': $('#profile_type').val() }, kivi.eval_json_result);
354       });
355       $('#add_mapping_from_upload').click(function(){
356         $.get('controller.pl?action_add_mapping_from_upload=1', $('form').serialize() , kivi.eval_json_result);
357       });
358       $('#csv_import_mappings').on('click', '.remove_line', function(){ $(this).closest('tr').remove(); if (1==$('#csv_import_mappings tr:visible').length) $('#mapping_empty').show() });
359     });
360     -->
361  </script>