epic-s6ts
[kivitendo-erp.git] / SL / Controller / SalesPurchase.pm
1 package SL::Controller::SalesPurchase;
2
3 use strict;
4 use parent qw(SL::Controller::Base);
5
6 use SL::DB::PurchaseInvoice;
7 use Carp;
8
9
10 sub action_check_duplicate_invnumber {
11   my ($self) = @_;
12
13   croak("no invnumber") unless $::form->{invnumber};
14   croak("no vendor")    unless $::form->{vendor_id};
15
16   my $exists_ap = SL::DB::Manager::PurchaseInvoice->find_by(
17                    invnumber => $::form->{invnumber},
18                    vendor_id => $::form->{vendor_id},
19                  );
20   # we are modifying a existing daily booking - allow this if
21   # booking conditions are not super strict
22   undef $exists_ap if ($::instance_conf->get_ap_changeable != 0
23                     && $exists_ap->gldate == DateTime->today_local);
24
25
26   $_[0]->render(\ !!$exists_ap, { type => 'text' });
27 }
28
29 1;
30
31 =pod
32
33 =encoding utf8
34
35 =head1 NAME
36
37 SL::Controller::SalesPurchase - Controller for JS driven actions
38
39 =head2 OVERVIEW
40
41 Generic Controller Class for validation function
42
43 =head1 FUNCTIONS
44
45 =over 2
46
47 =item C<action_check_duplicate_invnumber>
48
49 Needs C<form.invnumber> and C<form.vendor_id>
50
51 Returns true if a credit record with this invnumber for this vendor
52 already exists.
53
54 Example usage (js):
55
56  $.ajax({
57       url: 'controller.pl',
58       data: { action: 'SalesPurchase/check_duplicate_invnumber',
59               vendor_id    : $('#vendor_id').val(),
60               invnumber    : $('#invnumber').val()
61       },
62       method: "GET",
63       async: false,
64       dataType: 'text',
65       success: function(val) {
66         exists_invnumber = val;
67       }
68     });
69
70 =back