$self->{shipto}->trans_id($self->{cv}->id);
if( $self->{shipto}->shiptoname ne '' ) {
- $self->{shipto}->save();
+ $self->{shipto}->save(cascade => 1);
}
my $snumbers = $self->is_vendor() ? 'vendornumber_'. $self->{cv}->vendornumber : 'customernumber_'. $self->{cv}->customernumber;
sub action_ajaj_get_shipto {
my ($self) = @_;
- my $data = {
+ my $data = {};
+ $data->{shipto} = {
map(
{
my $name = 'shipto'. $_;
)
};
+ $data->{shipto_cvars} = $self->_prepare_cvar_configs_for_ajaj($self->{shipto}->cvars_by_config);
+
$self->render(\SL::JSON::to_json($data), { type => 'json', process => 0 });
}
$self->_copy_form_to_cvars(target => $self->{cv}, source => $::form->{cv_cvars});
$self->_copy_form_to_cvars(target => $self->{contact}, source => $::form->{contact_cvars});
+ $self->_copy_form_to_cvars(target => $self->{shipto}, source => $::form->{shipto_cvars});
}
sub _load_customer_vendor {
use SL::DB::MetaSetup::Shipto;
use SL::DB::Manager::Shipto;
+use SL::DB::Helper::CustomVariables (
+ module => 'ShipTo',
+ cvars_alias => 1,
+);
our @SHIPTO_VARIABLES = qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptogln shiptocontact
shiptophone shiptofax shiptoemail shiptodepartment_1 shiptodepartment_2);
this.selectShipto = function(params) {
var shiptoId = $('#shipto_shipto_id').val();
+ var url = 'controller.pl?action=CustomerVendor/ajaj_get_shipto&id='+ $('#cv_id').val() +'&db='+ $('#db').val() +'&shipto_id='+ shiptoId;
- if( shiptoId ) {
- var url = 'controller.pl?action=CustomerVendor/ajaj_get_shipto&id='+ $('#cv_id').val() +'&db='+ $('#db').val() +'&shipto_id='+ shiptoId;
+ $.getJSON(url, function(data) {
+ var shipto = data.shipto;
+ for(var key in shipto)
+ $('#shipto_'+ key).val(shipto[key])
- $.getJSON(url, function(data) {
- for(var key in data)
- $('#shipto_'+ key).val(data[key]);
+ kivi.CustomerVendor.setCustomVariablesFromAJAJ(data.shipto_cvars, 'shipto_cvars_');
+ if ( shiptoId )
$('#action_delete_shipto').show();
+ else
+ $('#action_delete_shipto').hide();
- if( params.onFormSet )
- params.onFormSet();
- });
- }
- else {
- $('#shipto :input').not(':button, :submit, :reset, :hidden').val('');
-
- $('#action_delete_shipto').hide();
-
- if( params.onFormSet )
+ if ( params.onFormSet )
params.onFormSet();
- }
+ });
};
this.selectDelivery = function(fromDate, toDate) {
}
};
- this.setCustomVariablesFromAJAJ = function(cvars) {
+ this.setCustomVariablesFromAJAJ = function(cvars, prefix) {
for (var key in cvars) {
var cvar = cvars[key];
- var $ctrl = $('#contact_cvars_'+ key);
+ var $ctrl = $('#' + prefix + key);
if (cvar.type == 'bool')
$ctrl.prop('checked', cvar.value == 1 ? 'checked' : '');
for(var key in contact)
$('#contact_'+ key).val(contact[key])
- kivi.CustomerVendor.setCustomVariablesFromAJAJ(data.contact_cvars);
+ kivi.CustomerVendor.setCustomVariablesFromAJAJ(data.contact_cvars, 'contact_cvars_');
if ( contactId )
$('#action_delete_contact').show();
[% L.input_tag('shipto.shiptoemail', SELF.shipto.shiptoemail, size = 45) %]
</td>
</tr>
+
+ [% shipto_cvars = SELF.shipto.cvars_by_config %]
+
+ [% IF ( shipto_cvars.size ) %]
+ <tr>
+ <td colspan="2">
+ <hr>
+ </td>
+ </tr>
+
+ [% FOREACH var = shipto_cvars %]
+ <tr>
+ <th align="right" valign="top" nowrap>[% var.config.description | html %]</th>
+
+ <td valign="top">
+ [% INCLUDE 'common/render_cvar_input.html'
+ cvar_name_prefix = 'shipto_cvars.'
+ %]
+ </td>
+ </tr>
+ [% END %]
+ [% END %]
</table>
[% L.button_tag('submitInputButton(this);', LxERP.t8('Delete Shipto'), name = 'action_delete_shipto', class = 'submit') %]