# save printed, emailed, queued
$form->save_status($dbh);
- $self->close_order_if_delivered('do_id' => $form->{id},
- 'type' => $form->{type} eq 'sales_delivery_order' ? 'sales' : 'purchase',
- 'dbh' => $dbh,);
+ $self->mark_order_if_delivered('do_id' => $form->{id},
+ 'type' => $form->{type} eq 'sales_delivery_order' ? 'sales' : 'purchase',
+ 'dbh' => $dbh,);
my $rc = $dbh->commit();
return $rc;
}
-sub close_order_if_delivered {
+sub mark_order_if_delivered {
$main::lxdebug->enter_sub();
my $self = shift;
$main::lxdebug->leave_sub();
}
+sub close_orders {
+ $main::lxdebug->enter_sub();
+
+ my $self = shift;
+ my %params = @_;
+
+ Common::check_params(\%params, qw(ids));
+
+ if (('ARRAY' ne ref $params{ids}) || !scalar @{ $params{ids} }) {
+ $main::lxdebug->leave_sub();
+ return;
+ }
+
+ my $myconfig = \%main::myconfig;
+ my $form = $main::form;
+
+ my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig);
+
+ my $query = qq|UPDATE delivery_orders SET closed = TRUE WHERE id IN (| . join(', ', ('?') x scalar(@{ $params{ids} })) . qq|)|;
+
+ do_query($form, $dbh, $query, map { conv_i($_) } @{ $params{ids} });
+
+ $dbh->commit() unless ($params{dbh});
+
+ $main::lxdebug->leave_sub();
+}
+
sub delete {
$main::lxdebug->enter_sub();
use SL::AM;
use SL::Common;
use SL::DBUtils;
+use SL::DO;
use SL::MoreCommon;
use List::Util qw(min);
Common::webdav_folder($form) if ($main::webdav);
- my $rc = 1;
+ my @close_do_ids = map { $_ * 1 } grep { $_ } split m/\s+/, $form->{close_do_ids};
+ if (scalar @close_do_ids) {
+ DO->close_orders('dbh' => $dbh,
+ 'ids' => \@close_do_ids);
+ }
+ my $rc = 1;
if (!$provided_dbh) {
$rc = $dbh->commit();
$dbh->disconnect();
use SL::CVar;
use SL::Common;
use SL::DBUtils;
+use SL::DO;
use SL::MoreCommon;
use Data::Dumper;
Common::webdav_folder($form) if ($main::webdav);
+ my @close_do_ids = map { $_ * 1 } grep { $_ } split m/\s+/, $form->{close_do_ids};
+
+ if (scalar @close_do_ids) {
+ DO->close_orders('dbh' => $dbh,
+ 'ids' => \@close_do_ids);
+ }
+
my $rc = 1;
if (!$provided_dbh) {
$dbh->commit();
check_do_access();
$auth->assert($form->{type} eq 'purchase_delivery_order' ? 'vendor_invoice_edit' : 'invoice_edit');
+ $form->{close_do_ids} = $form->{id};
+
$form->{deliverydate} = $form->{transdate};
$form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
$form->{duedate} = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
'back_button' => 1);
}
+ $form->{close_do_ids} = join ' ', @do_ids;
$form->{deliverydate} = $form->{transdate};
$form->{transdate} = $form->current_date(\%myconfig);
$form->{duedate} = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
</tr>
</table>
<br>
-|;
+| . $cgi->hidden('-name' => 'close_do_ids', '-default' => [$form->{close_do_ids}]);
$invdate = $form->datetonum($form->{invdate}, \%myconfig);
$closedto = $form->datetonum($form->{closedto}, \%myconfig);
$cgi->hidden("-name" => "callback", "-value" => $form->{callback})
. $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
. $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
+. $cgi->hidden('-name' => 'close_do_ids', '-default' => [$form->{close_do_ids}])
. qq|
</form>