2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.4 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2013 |
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
9 | CiviCRM is free software; you can copy, modify, and distribute it |
10 | under the terms of the GNU Affero General Public License |
11 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | CiviCRM is distributed in the hope that it will be useful, but |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16 | See the GNU Affero General Public License for more details. |
18 | You should have received a copy of the GNU Affero General Public |
19 | License and the CiviCRM Licensing Exception along |
20 | with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
26 <div class="batch-entry form-item">
28 {ts}Click Validate & Process below when you've entered all items for the batch. You can also Save & Continue Later at any time. Go to Administer > Customize Data and Screens > Profiles > Reserved Profiles > to add, remove or change the order of columns.{/ts}
30 {if $batchAmountMismatch}
31 <div class="status message status-warning">
33 class="icon alert-icon"></div> {ts}Total for amounts entered below does not match the expected batch total.{/ts}
35 <div class="crm-button crm-button_qf_Entry_upload_force-save">
36 {$form._qf_Entry_upload_force.html}
38 <div class="clear"></div>
40 <table class="form-layout-compressed batch-totals">
42 <td class="label">{ts}Total amount expected{/ts}</td>
43 <td class="right"><span class="batch-expected-total">{$batchTotal|crmMoney}</span></td>
46 <td class="label">{ts}Total amount entered{/ts}</td>
47 <td class="right">{$config->defaultCurrencySymbol} <span class="batch-actual-total"></span></td>
51 <div class="crm-copy-fields crm-grid-table" id="crm-batch-entry-table">
52 <div class="crm-grid-header">
53 <div class="crm-grid-cell"> </div>
54 <div class="crm-grid-cell">{ts}Contact{/ts}</div>
56 <div class="crm-grid-cell"> </div>
58 {foreach from=$fields item=field key=fieldName}
59 <div class="crm-grid-cell">
60 <img src="{$config->resourceBase}i/copy.png"
61 alt="{ts 1=$field.title}Click to copy %1 from row one to all rows.{/ts}"
62 fname="{$field.name}" class="action-icon"
63 title="{ts}Click here to copy the value in row one to ALL rows.{/ts}"/>{$field.title}
68 {section name='i' start=1 loop=$rowCount}
69 {assign var='rowNumber' value=$smarty.section.i.index}
70 <div class="{cycle values="odd-row,even-row"} selector-rows crm-grid-row" entity_id="{$rowNumber}">
71 <div class="compressed crm-grid-cell"><span class="batch-edit"></span></div>
72 {* contact select/create option*}
73 <div class="compressed crm-grid-cell">
74 {include file="CRM/Contact/Form/NewContact.tpl" blockNo = $rowNumber noLabel=true prefix="primary_" newContactCallback="updateContactInfo($rowNumber, 'primary_')"}
78 {$form.member_option.$rowNumber.html}
81 {foreach from=$fields item=field key=fieldName}
82 {assign var=n value=$field.name}
83 {if ( $fields.$n.data_type eq 'Date') or ( in_array( $n, array( 'thankyou_date', 'cancel_date', 'receipt_date', 'receive_date', 'join_date', 'membership_start_date', 'membership_end_date' ) ) ) }
84 <div class="compressed crm-grid-cell">
85 <span class="crm-batch-{$n}-{$rowNumber}">
86 {include file="CRM/common/jcalendar.tpl" elementName=$n elementIndex=$rowNumber batchUpdate=1}
89 {elseif $n eq 'soft_credit'}
90 <div class="compressed crm-grid-cell">
91 {include file="CRM/Contact/Form/NewContact.tpl" blockNo = $rowNumber noLabel=true prefix="soft_credit_"}
93 {elseif in_array( $fields.$n.html_type, array('Radio', 'CheckBox'))}
94 <div class="compressed crm-grid-cell"> {$form.field.$rowNumber.$n.html}</div>
96 <div class="compressed crm-grid-cell">{$form.field.$rowNumber.$n.html}</div>
102 <div class="crm-submit-buttons">{if $fields}{$form._qf_Batch_refresh.html}{/if} {$form.buttons.html}</div>
105 <script type="text/javascript">
107 cj('.selector-rows').change(function () {
109 'url': {/literal}"{crmURL p='civicrm/ajax/batch' h=0}"{literal}
112 cj("#Entry").ajaxSubmit(options);
115 cj('#crm-container').on('keyup change', '*.selector-rows', function () {
117 checkColumns(cj(this));
123 //calculate the actual total for the batch
124 calculateActualTotal();
126 cj('input[id*="_total_amount"]').bind('keyup change', function () {
127 calculateActualTotal();
130 {/literal}{if $batchType eq 1 }{literal}
131 // hide all dates if send receipt is checked
134 // hide the receipt date if send receipt is checked
135 cj('input[id*="][send_receipt]"]').change(function () {
136 showHideReceipt(cj(this));
139 {/literal}{else}{literal}
140 cj('select[id^="member_option_"]').each(function () {
141 if (cj(this).val() == 1) {
142 cj(this).attr('disabled', true);
146 // set payment info accord to membership type
147 cj('select[id*="_membership_type_0"]').change(function () {
148 setPaymentBlock(cj(this), null);
151 cj('select[id*="_membership_type_1"]').change(function () {
152 setPaymentBlock(cj(this), cj(this).val());
155 {/literal}{/if}{literal}
157 // line breaks between radio buttons and checkboxes
158 cj('input.form-radio').next().after('<br />');
159 cj('input.form-checkbox').next().after('<br />');
161 //set the focus on first element
162 cj('#primary_contact_1').focus();
166 function setPaymentBlock(form, memType) {
167 var rowID = form.closest('div.crm-grid-row').attr('entity_id');
168 var dataUrl = {/literal}"{crmURL p='civicrm/ajax/memType' h=0}"{literal};
171 memType = cj('select[id="field_' + rowID + '_membership_type_1"]').val();
174 cj.post(dataUrl, {mtype: memType}, function (data) {
175 cj('#field_' + rowID + '_financial_type').val(data.financial_type_id);
176 cj('#field_' + rowID + '_total_amount').val(data.total_amount).change();
180 function hideSendReceipt() {
181 cj('input[id*="][send_receipt]"]').each(function () {
182 showHideReceipt(cj(this));
186 function showHideReceipt(elem) {
187 var rowID = elem.closest('div.crm-grid-row').attr('entity_id');
188 if (elem.prop('checked')) {
189 cj('.crm-batch-receipt_date-' + rowID).hide();
192 cj('.crm-batch-receipt_date-' + rowID).show();
196 function validateRow() {
197 cj('.selector-rows').each(function () {
198 checkColumns(cj(this));
202 function checkColumns(parentRow) {
203 // show valid row icon if all required data is field
206 var errorExists = false;
207 var rowID = parentRow.closest('div.crm-grid-row').attr('entity_id');
209 parentRow.find('div .required').each(function () {
210 //special case to handle contact autocomplete select
211 var fieldId = cj(this).attr('id');
212 if (fieldId.substring(0, 16) == 'primary_contact_') {
213 // if display value is set then make sure we also check if contact id is set
214 if (!cj(this).val()) {
218 var contactIdElement = cj('input[name="primary_contact_select_id[' + rowID + ']"]');
219 if (cj(this).val() && !contactIdElement.val()) {
223 else if (cj(this).val() && contactIdElement.val()) {
224 // this is hack to remove error span because we are skipping this for autocomplete fields
225 cj(this).next('span.crm-error').remove();
230 if (!cj(this).val()) {
234 if (cj(this).hasClass('error') && (cj(this).hasClass('valid') || cj(this).hasClass('required'))) {
244 // this means user has entered some data
246 parentRow.find("div:first span").prop('class', 'batch-invalid');
249 if (inValidRow == 0 && validRow > 0) {
250 parentRow.find("div:first span").prop('class', 'batch-valid');
253 parentRow.find("div:first span").prop('class', 'batch-edit');
258 function calculateActualTotal() {
260 cj('input[id*="_total_amount"]').each(function () {
261 if (cj(this).val()) {
262 total += parseFloat(cj(this).val());
266 cj('.batch-actual-total').html(formatMoney(total));
269 //money formatting/localization
270 function formatMoney(amount) {
272 var t = '{/literal}{$config->monetaryThousandSeparator}{literal}';
273 var d = '{/literal}{$config->monetaryDecimalPoint}{literal}';
276 c = isNaN(c = Math.abs(c)) ? 2 : c,
277 d = d == undefined ? "," : d,
278 t = t == undefined ? "." : t, s = n < 0 ? "-" : "",
279 i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
280 j = (j = i.length) > 3 ? j % 3 : 0;
282 return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
285 function updateContactInfo(blockNo, prefix) {
286 var contactHiddenElement = 'input[name="' + prefix + 'contact_select_id[' + blockNo + ']"]';
287 var contactId = cj(contactHiddenElement).val();
289 var returnProperties = '';
290 var profileFields = new Array();
293 {foreach from=$contactFields item=val key=fldName}
294 var fldName = "{$fldName}";
296 if (returnProperties) {
297 returnProperties = returnProperties + ',';
299 var fld = fldName.split('-');
300 returnProperties = returnProperties + fld[0];
301 profileFields[fld[0]] = fldName;
307 CRM.api('Contact', 'get', {
309 'contact_id': contactId,
310 'return': returnProperties },
311 { success: function (data) {
312 cj.each(data.values[0], function (key, value) {
314 var actualFldName = profileFields[key];
315 if (key == 'country' || key == 'state_province') {
316 idFldName = key + '_id';
317 value = data.values[0][idFldName];
319 setFieldValue(actualFldName, value, blockNo)
322 // for membership batch entry based on contact we need to enable / disable
323 // add membership select
324 {/literal}{if $batchType eq 2}{literal}
325 CRM.api('Membership', 'get', {
327 'contact_id': contactId,
329 { success: function (data) {
330 if (data.count > 0) {
331 //get the information on membership type
332 var membershipTypeId = data.values[0].membership_type_id;
333 var membershipJoinDate = data.values[0].join_date;
334 CRM.api('MembershipType', 'get', {
336 'id': membershipTypeId
338 { success: function (data) {
339 var memTypeContactId = data.values[0].member_of_contact_id;
340 cj('select[id="member_option_' + blockNo + '"]').removeAttr('disabled').val(2);
341 cj('select[id="field_' + blockNo + '_membership_type_0"]').val(memTypeContactId).change();
342 cj('select[id="field_' + blockNo + '_membership_type_1"]').val(membershipTypeId).change();
343 setDateFieldValue('join_date', membershipJoinDate, blockNo)
349 {/literal}{/if}{literal}
355 * This function is use to setdefault elements via ajax
357 * @param fname string field name
360 function setFieldValue(fname, fieldValue, blockNo) {
361 var elementId = cj('[name="field[' + blockNo + '][' + fname + ']"]');
363 if (elementId.length == 0) {
364 elementId = cj('input[type=checkbox][name^="field[' + blockNo + '][' + fname + ']"][type!=hidden]');
367 // if element not found than return
368 if (elementId.length == 0) {
372 //check if it is date element
373 var isDateElement = elementId.attr('format');
375 // check if it is wysiwyg element
376 var editor = elementId.attr('editor');
378 //get the element type
379 var elementType = elementId.attr('type');
381 // set the value for all the elements, elements needs to be handled are
382 // select, checkbox, radio, date fields, text, textarea, multi-select
383 // wysiwyg editor, advanced multi-select ( to do )
384 if (elementType == 'radio') {
386 elementId.filter("[value=" + fieldValue + "]").prop("checked", true);
389 elementId.removeProp('checked');
393 if (elementType == 'checkbox') {
395 elementId.removeProp('checked');
397 cj.each(fieldValue, function (key, value) {
398 cj('input[name="field[' + blockNo + '][' + fname + '][' + value + ']"]').prop('checked', true);
406 var elemtId = elementId.attr('id');
407 oEditor = CKEDITOR.instances[elemtId];
408 oEditor.setData(htmlContent);
411 var elemtId = element.attr('id');
412 tinyMCE.get(elemtId).setContent(htmlContent);
416 case 'drupalwysiwyg':
419 elementId.val(fieldValue);
423 elementId.val(fieldValue);
428 // since we use different display field for date we also need to set it.
429 // also check for date time field and set the value correctly
430 if (isDateElement && fieldValue) {
431 setDateFieldValue(fname, fieldValue, blockNo)
435 function setDateFieldValue(fname, fieldValue, blockNo) {
436 var dateValues = fieldValue.split(' ');
438 var actualDateElement = cj('#field_' + blockNo + '_' + fname);
439 var date_format = actualDateElement.attr('format');
440 var altDateFormat = 'yy-mm-dd';
442 var actualDateValue = cj.datepicker.parseDate(altDateFormat, dateValues[0]);
444 // format date according to display field
445 var hiddenDateValue = cj.datepicker.formatDate('mm/dd/yy', actualDateValue);
447 actualDateElement.val(hiddenDateValue);
449 var displayDateValue = actualDateElement.val();
450 if (date_format != 'mm/dd/yy') {
451 displayDateValue = cj.datepicker.formatDate(date_format, actualDateValue);
454 cj('#field_' + blockNo + '_' + fname + '_display').val(displayDateValue);
456 // need to fix time formatting
458 cj('#field_' + blockNo + '_' + fname + '_time').val(dateValues[1].substr(0, 5));
465 {*include batch copy js js file*}
466 {include file="CRM/common/batchCopy.tpl"}