Revision dce860e3
Von Moritz Bunkus vor fast 14 Jahren hinzugefügt
SL/DB/Invoice.pm | ||
---|---|---|
61 | 61 |
|
62 | 62 |
__PACKAGE__->meta->make_attr_helpers(taxamount => 'numeric(15,5)'); |
63 | 63 |
|
64 |
sub closed { |
|
65 |
my ($self) = @_; |
|
66 |
return $self->paid >= $self->amount; |
|
67 |
} |
|
68 |
|
|
69 |
sub post { |
|
70 |
my ($self, %params) = @_; |
|
71 |
|
|
72 |
$self->db->do_transaction(sub { |
|
73 |
1; # dummy instruction for Emacs ;) |
|
74 |
|
|
75 |
my %data = $self->calculate_prices_and_taxes; |
|
76 |
|
|
77 |
$self->_post_create_assemblyitem_entries($data{assembly_items}); |
|
78 |
|
|
79 |
$self->save; |
|
80 |
|
|
81 |
$self->_post_add_acctrans($data{amounts_cogs}); |
|
82 |
$self->_post_add_acctrans($data{amounts}); |
|
83 |
$self->_post_add_acctrans($data{taxes}); |
|
84 |
|
|
85 |
$self->_post_update_allocated($data{allocated}); |
|
86 |
|
|
87 |
die; |
|
88 |
}); |
|
89 |
} |
|
90 |
|
|
91 |
sub _post_add_acctrans { |
|
92 |
my ($self, $entries) = @_; |
|
93 |
|
|
94 |
while (my ($chart_id, $spec) = each %{ $entries }) { |
|
95 |
$spec = { taxkey => 0, amount => $spec } unless ref $spec; |
|
96 |
SL::DB::AccTrans->new(trans_id => $self->id, |
|
97 |
chart_id => $chart_id, |
|
98 |
amount => $spec->{amount}, |
|
99 |
taxkey => $spec->{taxkey}, |
|
100 |
project_id => $self->project_id, |
|
101 |
transdate => $self->transdate)->save; |
|
102 |
} |
|
103 |
} |
|
104 |
|
|
105 |
sub _post_create_assemblyitem_entries { |
|
106 |
my ($self, $assembly_entries) = @_; |
|
107 |
|
|
108 |
my $items = $self->invoiceitems; |
|
109 |
my @new_items; |
|
110 |
|
|
111 |
my $item_idx = 0; |
|
112 |
foreach my $item (@{ $items }) { |
|
113 |
next if $item->assemblyitem; |
|
114 |
|
|
115 |
push @new_items, $item; |
|
116 |
$item_idx++; |
|
117 |
|
|
118 |
foreach my $assembly_item (@{ $assembly_entries->[$item_idx] || [ ] }) { |
|
119 |
push @new_items, SL::DB::InvoiceItem->new(parts_id => $assembly_item->{part}, |
|
120 |
description => $assembly_item->{part}->description, |
|
121 |
unit => $assembly_item->{part}->unit, |
|
122 |
qty => $assembly_item->{qty}, |
|
123 |
allocated => $assembly_item->{allocated}, |
|
124 |
sellprice => 0, |
|
125 |
fxsellprice => 0, |
|
126 |
assemblyitem => 't'); |
|
127 |
} |
|
128 |
} |
|
129 |
|
|
130 |
$self->invoiceitems(\@new_items); |
|
131 |
} |
|
132 |
|
|
133 |
sub _post_update_allocated { |
|
134 |
my ($self, $allocated) = @_; |
|
135 |
|
|
136 |
while (my ($invoice_id, $diff) = each %{ $allocated }) { |
|
137 |
SL::DB::Manager::InvoiceItem->update_all(set => { allocated => { sql => [ 'allocated + ?', $diff ] } }, |
|
138 |
where => [ id => $invoice_id ]); |
|
139 |
} |
|
140 |
} |
|
141 |
|
|
142 |
>>>>>>> b6be290... Prototypisiertes Buchen von Rechnungen |
|
64 | 143 |
1; |
Auch abrufbar als: Unified diff
Prototypisiertes Buchen von Rechnungen
Conflicts: