Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision ab725987

Von Kivitendo Admin vor fast 8 Jahren hinzugefügt

  • ID ab725987652635d307d17f6dbf7029184f3a48bd
  • Vorgänger a50663d8
  • Nachfolger d975f05c

SL::Dev::Record - neue Funktion create_credit_note

Unterschiede anzeigen:

SL/Dev/Record.pm
2 2

  
3 3
use strict;
4 4
use base qw(Exporter);
5
our @EXPORT = qw(create_invoice_item create_sales_invoice create_order_item  create_sales_order create_purchase_order create_delivery_order_item create_sales_delivery_order create_project);
5
our @EXPORT = qw(create_invoice_item create_sales_invoice create_credit_note create_order_item  create_sales_order create_purchase_order create_delivery_order_item create_sales_delivery_order create_project);
6 6

  
7 7
use SL::DB::Invoice;
8 8
use SL::DB::InvoiceItem;
......
15 15
use DateTime;
16 16

  
17 17
my %record_type_to_item_type = ( sales_invoice        => 'SL::DB::InvoiceItem',
18
                                 credit_note          => 'SL::DB::InvoiceItem',
18 19
                                 sales_order          => 'SL::DB::OrderItem',
19 20
                                 purchase_order       => 'SL::DB::OrderItem',
20 21
                                 sales_delivery_order => 'SL::DB::DeliveryOrderItem',
......
51 52
  return $invoice;
52 53
}
53 54

  
55
sub create_credit_note {
56
  my (%params) = @_;
57

  
58
  my $record_type = 'credit_note';
59
  my $invoiceitems = delete $params{invoiceitems} // _create_two_items($record_type);
60
  _check_items($invoiceitems, $record_type);
61

  
62
  my $customer = delete $params{customer} // SL::Dev::CustomerVendor::create_customer(name => 'Testcustomer')->save;
63
  die "illegal customer" unless defined $customer && ref($customer) eq 'SL::DB::Customer';
64

  
65
  # adjust qty for credit note items
66
  $_->qty( $_->qty * -1) foreach @{$invoiceitems};
67

  
68
  my $invoice = SL::DB::Invoice->new(
69
    invoice      => 1,
70
    type         => 'credit_note',
71
    customer_id  => $customer->id,
72
    taxzone_id   => $customer->taxzone->id,
73
    invnumber    => delete $params{invnumber}   // undef,
74
    currency_id  => $params{currency_id} // $::instance_conf->get_currency_id,
75
    taxincluded  => $params{taxincluded} // 0,
76
    employee_id  => $params{employee_id} // SL::DB::Manager::Employee->current->id,
77
    salesman_id  => $params{employee_id} // SL::DB::Manager::Employee->current->id,
78
    transdate    => $params{transdate}   // DateTime->today_local->to_kivitendo,
79
    payment_id   => $params{payment_id}  // undef,
80
    gldate       => DateTime->today,
81
    invoiceitems => $invoiceitems,
82
  );
83
  $invoice->assign_attributes(%params) if %params;
84

  
85
  $invoice->post;
86
  return $invoice;
87
}
88

  
54 89
sub create_sales_delivery_order {
55 90
  my (%params) = @_;
56 91

  
......
254 289
    taxincluded => 1,
255 290
  );
256 291

  
292
=head2 C<create_credit_note %PARAMS>
293

  
294
Create a credit note (sales). Use positive quantities when adding items.
295

  
296
Example including creation of parts and of credit_note
297
  my $part1 = SL::Dev::Part::create_part(   partnumber => 'T4254')->save;
298
  my $part2 = SL::Dev::Part::create_service(partnumber => 'Serv1')->save;
299
  my $credit_note = SL::Dev::Record::create_credit_note(
300
    invnumber    => '34',
301
    taxincluded  => 0,
302
    invoiceitems => [ SL::Dev::Record::create_invoice_item(part => $part1, qty =>  3, sellprice => 70),
303
                      SL::Dev::Record::create_invoice_item(part => $part2, qty => 10, sellprice => 50),
304
                    ]
305
  );
306

  
257 307
=head2 C<create_sales_order %PARAMS>
258 308

  
259 309
Examples:

Auch abrufbar als: Unified diff