• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ledgersmb / LedgerSMB / 2340

pending completion
2340

push

circleci

GitHub
Bump cssnano from 5.0.4 to 5.0.5

9446 of 21212 relevant lines covered (44.53%)

812.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

6.12
/old/bin/pe.pl
1
#=====================================================================
2
# LedgerSMB
3
# Small Medium Business Accounting software
4
# http://www.ledgersmb.org/
5
#
6
#
7
# See COPYRIGHT file for copyright information
8
#======================================================================
9
#
10
# This file has NOT undergone whitespace cleanup.
11
#
12
#======================================================================
13
#
14
# project/job administration
15
# partsgroup administration
16
# translation maintainance
17
#
18
#======================================================================
19

20
package lsmb_legacy;
21
use LedgerSMB::PE;
1✔
22
use LedgerSMB::AA;
1✔
23
use LedgerSMB::OE;
1✔
24

25
# end of main
26

27
sub add {
28

29
    # construct callback
30
    $form->{callback} = "$form->{script}?action=add&type=$form->{type}"
31
      unless $form->{callback};
×
32

33
    &{"prepare_$form->{type}"};
×
34

35
    $form->{orphaned} = 1;
×
36
    &display_form;
×
37

38
}
39

40
sub edit {
41

42
    &{"prepare_$form->{type}"};
×
43
    &display_form;
×
44

45
}
46

47
sub prepare_partsgroup {
48
    PE->get_partsgroup(\%$form)
49
      if $form->{id};
×
50
}
51
sub prepare_pricegroup {
52
    PE->get_pricegroup( \%myconfig, \%$form )
53
      if $form->{id};
×
54
}
55

56

57
sub save {
58

59
    if ( $form->{translation} ) {
×
60
        PE->save_translation( \%myconfig, \%$form );
×
61
        $form->redirect( $locale->text('Translations saved!') );
×
62
        $form->finalize_request();
×
63
    }
64

65
    if ( $form->{type} eq 'partsgroup' ) {
×
66
        $form->isblank( "partsgroup", $locale->text('Group missing!') );
×
67
        PE->save_partsgroup( \%myconfig, \%$form );
×
68
        $form->redirect( $locale->text('Group saved!') );
×
69
    }
70

71
    elsif ( $form->{type} eq 'pricegroup' ) {
72
        $form->isblank( "pricegroup", $locale->text('Pricegroup missing!') );
×
73
        PE->save_pricegroup( \%myconfig, \%$form );
×
74
        $form->redirect( $locale->text('Pricegroup saved!') );
×
75
    }
76
}
77

78
sub delete {
79

80
    if ( $form->{translation} ) {
×
81
        PE->delete_translation( \%myconfig, \%$form );
×
82
        $form->redirect( $locale->text('Translation deleted!') );
×
83

84
    }
85
    else {
86

87
        if ( $form->{type} eq 'partsgroup' ) {
×
88
            PE->delete_partsgroup( \%myconfig, \%$form );
×
89
            $form->redirect( $locale->text('Group deleted!') );
×
90
        }
91
        elsif ( $form->{type} eq 'pricegroup' ) {
92
            PE->delete_pricegroup( \%myconfig, \%$form );
×
93
            $form->redirect( $locale->text('Pricegroup deleted!') );
×
94
        }
95
    }
96

97
}
98

99
sub partsgroup_header {
100

101
    $form->{action} =~ s/_.*//;
×
102
    # $locale->text('Add Group')
103
    # $locale->text('Edit Group')
104
    $form->{title} = $locale->maketext( ucfirst $form->{action} . " Group" );
×
105

106

107
    $form->{partsgroup} = $form->quote( $form->{partsgroup} );
×
108
    PE->partsgroups(\%myconfig, $form);
×
109

110
    $form->header;
×
111

112
    print qq|
×
113
<body class="lsmb">
114

115
<form method="post" data-dojo-type="lsmb/Form" action=$form->{script}>
116

117
<input type=hidden name=id value=$form->{id}>
118
<input type=hidden name=type value=$form->{type}>
119

120
<table width=100%>
121
  <tr>
122
    <th class=listtop>$form->{title}</th>
123
  </tr>
124
  <tr height="5"></tr>
125
  <tr>
126
    <td>
127
      <table width=100%>
128
    <tr>
129
          <th align="right">| . $locale->text('Parent') . qq|</th>
130
          <td><select data-dojo-type="dijit/form/Select"
131
                      id='parent' name='parent'>
132
              <option>&nbsp;</option>|;
133
              for my $pg (@{$form->{item_list}}){
×
134
                  my $selected = '';
×
135
                  $selected = 'SELECTED="SELECTED"'
136
                         if $form->{parent} == $pg->{id};
×
137
                  print qq|<option value='$pg->{id}' $selected>
×
138
                                  $pg->{partsgroup} </option>|;
139
              }
140
      print qq|</select>
×
141
          <th align="right">| . $locale->text('Group') . qq|</th>
142

143
          <td><input data-dojo-type="dijit/form/TextBox" name=partsgroup size=30 value="$form->{partsgroup}"></td>
144
    </tr>
145
      </table>
146
    </td>
147
  </tr>
148
  <tr>
149
    <td colspan=2><hr size=3 noshade></td>
150
  </tr>
151
</table>
152
|;
153

154
}
155

156
sub partsgroup_footer {
157

158
    $form->hide_form(qw(callback path login sessionid));
×
159

160
    if ( $myconfig{acs} !~ /Goods \& Services--Add Group/ ) {
×
161
        print qq|
×
162
<button data-dojo-type="dijit/form/Button" type="submit" class="submit" name="action" value="save">|
163
          . $locale->text('Save')
164
          . qq|</button>
165
|;
166

167
        if ( $form->{id} && $form->{orphaned} ) {
×
168
            print qq|
×
169
<button data-dojo-type="dijit/form/Button" type="submit" class="submit" name="action" value="delete">|
170
              . $locale->text('Delete')
171
              . qq|</button>|;
172
        }
173
    }
174

175
    print qq|
×
176
</form>
177

178
</body>
179
</html>
180
|;
181

182
}
183

184
sub pricegroup_header {
185

186
    $form->{action} =~ s/_.*//;
×
187
    # $locale->text('Add Pricegroup')
188
    # $locale->text('Edit Pricegroup')
189
    $form->{title} = $locale->maketext(
190
        ucfirst $form->{action} . " Pricegroup" );
×
191

192
    $form->{pricegroup} = $form->quote( $form->{pricegroup} );
×
193

194
    $form->header;
×
195

196
    print qq|
×
197
<body class="lsmb">
198

199
<form method="post" data-dojo-type="lsmb/Form" action=$form->{script}>
200

201
<input type=hidden name=id value=$form->{id}>
202
<input type=hidden name=type value=$form->{type}>
203

204
<table width=100%>
205
  <tr>
206
    <th class=listtop>$form->{title}</th>
207
  </tr>
208
  <tr height="5"></tr>
209
  <tr>
210
    <td>
211
      <table width=100%>
212
    <tr>
213
      <th align=right>| . $locale->text('Pricegroup') . qq|</th>
214

215
          <td><input data-dojo-type="dijit/form/TextBox" name=pricegroup size=30 value="$form->{pricegroup}"></td>
216
    </tr>
217
      </table>
218
    </td>
219
  </tr>
220
  <tr>
221
    <td colspan=2><hr size=3 noshade></td>
222
  </tr>
223
</table>
224
|;
225

226
}
227

228
sub pricegroup_footer {
229

230
    $form->hide_form(qw(callback path login sessionid));
×
231

232
    if ( $myconfig{acs} !~ /Goods \& Services--Add Pricegroup/ ) {
×
233
        print qq|
×
234
<button data-dojo-type="dijit/form/Button" type="submit" class="submit" name="action" value="save">|
235
          . $locale->text('Save')
236
          . qq|</button>
237
|;
238

239
        if ( $form->{id} && $form->{orphaned} ) {
×
240
            print qq|
×
241
<button data-dojo-type="dijit/form/Button" type="submit" class="submit" name="action" value="delete">|
242
              . $locale->text('Delete')
243
              . qq|</button>|;
244
        }
245
    }
246

247
    print qq|
×
248
</form>
249

250
</body>
251
</html>
252
|;
253

254
}
255

256
sub translation {
257

258
    if ( $form->{translation} eq 'description' ) {
×
259
        $form->{title}  = $locale->text('Description Translations');
×
260
        $sort           = qq|<input type=hidden name=sort value=partnumber>|;
×
261
        $form->{number} = "partnumber";
×
262
        $number         = qq|
×
263
        <tr>
264
          <th align=right nowrap>| . $locale->text('Number') . qq|</th>
265
          <td><input data-dojo-type="dijit/form/TextBox" name=partnumber size=20></td>
266
        </tr>
267
|;
268
    }
269

270
    if ( $form->{translation} eq 'partsgroup' ) {
×
271
        $form->{title} = $locale->text('Group Translations');
×
272
        $sort = qq|<input type=hidden name=sort value=partsgroup>|;
×
273
    }
274

275
    if ( $form->{translation} eq 'project' ) {
×
276
        $form->{title}  = $locale->text('Project Description Translations');
×
277
        $form->{number} = "projectnumber";
×
278
        $sort           = qq|<input type=hidden name=sort value=projectnumber>|;
×
279
        $number         = qq|
×
280
        <tr>
281
          <th align=right nowrap>| . $locale->text('Project Number') . qq|</th>
282
          <td><input data-dojo-type="dijit/form/TextBox" name=projectnumber size=20></td>
283
        </tr>
284
|;
285
    }
286

287
    $form->header;
×
288

289
    print qq|
×
290
<body class="lsmb">
291

292
<form method="post" data-dojo-type="lsmb/Form" action=$form->{script}>
293
|;
294

295
    $form->hide_form(qw(translation title number));
×
296

297
    print qq|
×
298

299
<table width="100%">
300
  <tr><th class=listtop>$form->{title}</th></tr>
301
  <tr height="5"></tr>
302
  <tr valign=top>
303
    <td>
304
      <table>
305
        $number
306
        <tr>
307
          <th align=right nowrap>| . $locale->text('Description') . qq|</th>
308
          <td colspan=3><input data-dojo-type="dijit/form/TextBox" name=description size=40></td>
309
        </tr>
310
      </table>
311
    </td>
312
  </tr>
313
  <tr><td><hr size=3 noshade></td></tr>
314
</table>
315

316
<input type=hidden name=nextsub value=list_translations>
317
$sort
318
|;
319

320
    $form->hide_form(qw(path login sessionid));
×
321

322
    print qq|
×
323

324
<br>
325
<button data-dojo-type="dijit/form/Button" class="submit" type="submit" name="action" value="continue">|
326
      . $locale->text('Continue')
327
      . qq|</button>
328
</form>
329

330
</body>
331
</html>
332
|;
333

334
}
335

336
sub list_translations {
337

338
    $title = $form->escape( $form->{title}, 1 );
×
339

340
    $callback =
×
341
"$form->{script}?action=list_translations&translation=$form->{translation}&number=$form->{number}&title=$title";
342

343
    if ( $form->{"$form->{number}"} ) {
×
344
        $callback .= qq|&$form->{number}=$form->{"$form->{number}"}|;
×
345
        $option .=
×
346
          $locale->text('Number') . qq| : $form->{"$form->{number}"}<br>|;
347
    }
348
    if ( $form->{description} ) {
×
349
        $callback .= "&description=$form->{description}";
×
350
        $description = $form->{description};
×
351
        $description =~ s/\r?\n/<br>/g;
×
352
        $option .=
×
353
          $locale->text('Description') . qq| : $form->{description}<br>|;
354
    }
355

356
    if ( $form->{translation} eq 'partsgroup' ) {
×
357
        @column_index = qw(description language translation);
×
358
        $form->{sort} = "";
×
359
    }
360
    else {
361
        @column_index =
×
362
          $form->sort_columns( "$form->{number}", "description", "language",
363
            "translation" );
364
    }
365

366
    &{"PE::$form->{translation}_translations"}( "", \%myconfig, \%$form );
×
367

368
    $callback .= "&direction=$form->{direction}&oldsort=$form->{oldsort}";
×
369

370
    $href = $callback;
×
371

372
    $form->sort_order();
×
373

374
    $callback =~ s/(direction=).*\&{1}/$1$form->{direction}\&/;
×
375

376
    $column_header{"$form->{number}"} =
×
377
        qq|<th nowrap><a class=listheading href=$href&sort=$form->{number}>|
378
      . $locale->text('Number')
379
      . qq|</a></th>|;
380
    $column_header{description} =
381
      qq|<th nowrap width=40%><a class=listheading href=$href&sort=description>|
×
382
      . $locale->text('Description')
383
      . qq|</a></th>|;
384
    $column_header{language} =
385
        qq|<th nowrap class=listheading>|
×
386
      . $locale->text('Language')
387
      . qq|</a></th>|;
388
    $column_header{translation} =
389
        qq|<th nowrap width=40% class=listheading>|
×
390
      . $locale->text('Translation')
391
      . qq|</a></th>|;
392

393
    $form->header;
×
394

395
    print qq|
×
396
<body class="lsmb">
397

398
<table width=100%>
399
  <tr>
400
    <th class=listtop>$form->{title}</th>
401
  </tr>
402
  <tr height="5"></tr>
403

404
  <tr><td>$option</td></tr>
405

406
  <tr>
407
    <td>
408
      <table width=100%>
409
        <tr class=listheading>
410
|;
411

412
    for (@column_index) { print "\n$column_header{$_}" }
×
413

414
    print qq|
×
415
        </tr>
416
  |;
417

418
    # add order to callback
419
    $form->{callback} = $callback .= "&sort=$form->{sort}";
×
420

421
    # escape callback for href
422
    $callback = $form->escape($callback);
×
423

424
    if ( @{ $form->{translations} } ) {
×
425
        $sameitem = $form->{translations}->[0]->{ $form->{sort} };
×
426
    }
427

428
    foreach my $ref ( @{ $form->{translations} } ) {
×
429

430
        $ref->{description} =~ s/\r?\n/<br>/g;
×
431

432
        for (@column_index) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
×
433

434
        $column_data{description} =
435
"<td><a href=$form->{script}?action=edit_translation&translation=$form->{translation}&number=$form->{number}&id=$ref->{id}&callback=$callback>$ref->{description}&nbsp;</a></td>";
×
436

437
        $i++;
×
438
        $i %= 2;
×
439
        print "<tr class=listrow$i>";
×
440

441
        for (@column_index) { print "\n$column_data{$_}" }
×
442

443
        print qq|
×
444
    </tr>
445
|;
446

447
    }
448

449
    print qq|
×
450
      </table>
451
    </td>
452
  </tr>
453
  <tr><td><hr size=3 noshade></td></tr>
454
</table>
455

456
|;
457

458
    print qq|
×
459

460
<br>
461

462
<form method="post" data-dojo-type="lsmb/Form" action=$form->{script}>
463

464
<input name=callback type=hidden value="$form->{callback}">
465
|;
466

467
    $form->hide_form(qw(path login sessionid));
×
468

469
    print qq|
×
470
  </form>
471

472
</body>
473
</html>
474
|;
475

476
}
477

478
sub edit_translation {
479

480
    &{"PE::$form->{translation}_translations"}( "", \%myconfig, \%$form );
×
481

482
    $form->error( $locale->text('Languages not defined!') )
483
      unless @{ $form->{all_language} };
×
484

485
    $form->{selectlanguage} = qq|<option></option>\n|;
×
486
    for ( @{ $form->{all_language} } ) {
×
487
        $form->{selectlanguage} .=
488
          qq|<option value="$_->{code}">$_->{description}</option>\n|;
×
489
    }
490

491
    $form->{"$form->{number}"} =
492
      $form->{translations}->[0]->{"$form->{number}"};
×
493
    $form->{description} = $form->{translations}->[0]->{description};
×
494
    $form->{description} =~ s/\r?\n/<br>/g;
×
495

496
    shift @{ $form->{translations} };
×
497

498
    $i = 1;
×
499
    foreach my $row ( @{ $form->{translations} } ) {
×
500
        $form->{"language_code_$i"} = $row->{code};
×
501
        $form->{"translation_$i"}   = $row->{translation};
×
502
        $i++;
×
503
    }
504
    $form->{translation_rows} = $i - 1;
×
505

506
    $form->{title} = $locale->text('Edit Description Translations');
×
507

508
    &translation_header;
×
509
    &translation_footer;
×
510

511
}
512

513
sub translation_header {
514

515
    $form->{translation_rows}++;
×
516

517
    $form->{selectlanguage} = $form->unescape( $form->{selectlanguage} );
×
518
    foreach my $i ( 1 .. $form->{translation_rows} ) {
×
519
        $form->{"selectlanguage_$i"} = $form->{selectlanguage};
×
520
        if ( $form->{"language_code_$i"} ) {
×
521
            $form->{"selectlanguage_$i"} =~
×
522
              s/(<option value="\Q$form->{"language_code_$i"}\E")/$1 selected/;
523
        }
524
    }
525

526
    $form->{selectlanguage} = $form->escape( $form->{selectlanguage}, 1 );
×
527

528
    $form->header;
×
529

530
    print qq|
531
<body class="lsmb">
532

533
<form method="post" data-dojo-type="lsmb/Form" action=$form->{script}>
534

535
<input type=hidden name=$form->{number} value="|
536
      . $form->quote( $form->{"$form->{number}"} ) . qq|">
537
<input type=hidden name=description value="|
538
      . $form->quote( $form->{description} ) . qq|">
×
539
|;
540

541
    $form->hide_form(
×
542
        qw(id trans_id selectlanguage translation_rows number translation title)
543
    );
544

545
    print qq|
×
546

547
<table width="100%">
548
  <tr><th class=listtop>$form->{title}</th></tr>
549
  <tr height="5"></tr>
550
  <tr valign=top>
551
    <td>
552
      <table width=100%>
553
        <tr>
554
          <td align=left>$form->{"$form->{number}"}</th>
555
      <td align=left>$form->{description}</th>
556
        </tr>
557
        <tr>
558
    <tr>
559
      <th class=listheading>| . $locale->text('Language') . qq|</th>
560
      <th class=listheading>| . $locale->text('Translation') . qq|</th>
561
    </tr>
562
|;
563

564
    foreach my $i ( 1 .. $form->{translation_rows} ) {
×
565

566
        if ( ( $rows = $form->numtextrows( $form->{"translation_$i"}, 40 ) ) >
×
567
            1 )
568
        {
569
            $translation =
×
570
qq|<textarea data-dojo-type="dijit/form/Textarea" name="translation_$i" rows=$rows cols=40 wrap=soft>$form->{"translation_$i"}</textarea>|;
571
        }
572
        else {
573
            $translation =
×
574
qq|<input data-dojo-type="dijit/form/TextBox" name="translation_$i" size=40 value="$form->{"translation_$i"}">|;
575
        }
576

577
        print qq|
×
578
    <tr valign=top>
579
      <td><select data-dojo-type="dijit/form/Select" id="language-code-$i" name="language_code_$i">$form->{"selectlanguage_$i"}</select></td>
580
      <td>$translation</td>
581
    </tr>
582
|;
583
    }
584

585
    print qq|
×
586
      </table>
587
    </td>
588
  </tr>
589
  <tr>
590
    <td><hr size=3 noshade></td>
591
  </tr>
592
</table>
593
|;
594

595
}
596

597
sub translation_footer {
598

599
    $form->hide_form(qw(path login sessionid callback));
×
600

601
    %button = (
×
602
        'update' => { ndx => 1,  key => 'U', value => $locale->text('Update') },
603
        'save'   => { ndx => 3,  key => 'S', value => $locale->text('Save') },
604
        'delete' => { ndx => 16, key => 'D', value => $locale->text('Delete') },
605
    );
606

607
    if ( !$form->{trans_id} ) {
×
608
        delete $button{'delete'};
×
609
    }
610

611
    for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
×
612
        $form->print_button( \%button, $_ );
×
613
    }
614

615
    print qq|
×
616

617
  </form>
618

619
</body>
620
</html>
621
|;
622

623
}
624

625
sub update {
626

627
    if ( $form->{translation} ) {
×
628
        @flds  = qw(language translation);
×
629
        $count = 0;
×
630
        @a     = ();
×
631
        foreach my $i ( 1 .. $form->{translation_rows} ) {
×
632
            if ( $form->{"language_code_$i"} ne "" ) {
×
633
                push @a, {};
×
634
                $j = $#a;
×
635

636
                for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
×
637
                $count++;
×
638
            }
639
        }
640
        $form->redo_rows( \@flds, \@a, $count, $form->{translation_rows} );
×
641
        $form->{translation_rows} = $count;
×
642

643
        &translation_header;
×
644
        &translation_footer;
×
645

646
        $form->finalize_request();
×
647

648
    }
649

650
    &display_form;
×
651

652
}
653

654
sub select_name {
655

656
    $label = ucfirst $form->{vc};
×
657

658
    @column_index = qw(ndx name address);
×
659
    $column_data{ndx} = qq|<th>&nbsp;</th>|;
×
660
    $column_data{name} =
661
      qq|<th class=listheading>| . $locale->maketext($label) . qq|</th>|;
×
662
    $column_data{address} =
663
        qq|<th class=listheading colspan=5>|
×
664
      . $locale->text('Address')
665
      . qq|</th>|;
666

667
    $form->header;
×
668
    $title = $locale->text('Select from one of the names below');
×
669
    print qq|
×
670
<body class="lsmb">
671

672
<form method="post" data-dojo-type="lsmb/Form" action=$form->{script}>
673

674
<table width=100%>
675
  <tr>
676
    <th class=listtop>$title</th>
677
  </tr>
678
  <tr space=5></tr>
679
  <tr>
680
    <td>
681
      <table width=100%>
682
    <tr class=listheading>|;
683

684
    for (@column_index) { print "\n$column_data{$_}" }
×
685

686
    print qq|
×
687
    </tr>
688
|;
689

690
    @column_index = qw(ndx name address city state zipcode country);
×
691

692
    my $i = 0;
×
693
    foreach my $ref ( @{ $form->{name_list} } ) {
×
694
        $checked = ( $i++ ) ? "" : "checked";
×
695

696
        $ref->{name} = $form->quote( $ref->{name} );
×
697

698
        $column_data{ndx} =
699
qq|<td><input name=ndx class=radio type=radio data-dojo-type="dijit/form/RadioButton" value=$i $checked></td>|;
×
700
        $column_data{name} =
701
qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
×
702
        $column_data{address} = qq|<td>$ref->{address1} $ref->{address2}</td>|;
×
703
        for (qw(city state zipcode country)) {
×
704
            $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>|;
×
705
        }
706

707
        $j++;
×
708
        $j %= 2;
×
709
        print qq|
×
710
    <tr class=listrow$j>|;
711

712
        for (@column_index) { print "\n$column_data{$_}" }
×
713

714
        print qq|
×
715
    </tr>
716

717
<input name="new_id_$i" type=hidden value=$ref->{id}>
718

719
|;
720

721
    }
722

723
    print qq|
×
724
      </table>
725
    </td>
726
  </tr>
727
  <tr>
728
    <td><hr size=3 noshade></td>
729
  </tr>
730
</table>
731

732
<input name=lastndx type=hidden value=$i>
733

734
|;
735

736
    # delete variables
737
    for (qw(action nextsub name_list)) { delete $form->{$_} }
×
738

739
    $form->hide_form;
×
740

741
    print qq|
×
742
<input type="hidden" name="nextsub" value="name_selected">
743
<br>
744
<button data-dojo-type="dijit/form/Button" class="submit" type="submit" name="action" value="continue">|
745
      . $locale->text('Continue')
746
      . qq|</button>
747
</form>
748

749
</body>
750
</html>
751
|;
752

753
}
754

755
sub name_selected {
756

757
    # replace the variable with the one checked
758

759
    # index for new item
760
    $i = $form->{ndx};
×
761

762
    $form->{ $form->{vc} } = $form->{"new_name_$i"};
×
763
    $form->{"$form->{vc}_id"} = $form->{"new_id_$i"};
×
764
    $form->{"old$form->{vc}"} =
×
765
      qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
766

767
    # delete all the new_ variables
768
    foreach my $i ( 1 .. $form->{lastndx} ) {
×
769
        for (qw(id name)) { delete $form->{"new_${_}_$i"} }
×
770
    }
771

772
    for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
×
773

774
    &display_form;
×
775

776
}
777

778
sub display_form {
779

780
    &{"$form->{type}_header"};
×
781
    &{"$form->{type}_footer"};
×
782

783
}
784

785
sub continue { &{ $form->{nextsub} } }
×
786

787
sub add_group      { &add }
×
788
sub add_project    { &add }
×
789
sub add_job        { &add }
×
790
sub add_pricegroup { &add }
×
791

792
sub project_sales_order {
793

794
    PE->project_sales_order( \%myconfig, \%$form );
1✔
795

796
    if ( @{ $form->{all_years} } ) {
1✔
797
        $form->{selectaccountingyear} = "<option></option>\n";
×
798
        for ( @{ $form->{all_years} } ) {
×
799
            $form->{selectaccountingyear} .= qq|<option>$_</option>\n|;
×
800
        }
801

802
        $form->{selectaccountingmonth} = "<option></option>\n";
×
803
        for ( sort keys %{ $form->{all_month} } ) {
×
804
            $form->{selectaccountingmonth} .=
805
              qq|<option value=$_>|
806
              . $locale->maketext( $form->{all_month}{$_} ) . qq|</option>\n|;
×
807
        }
808

809
        $selectfrom = qq|
×
810
        <tr>
811
      <th align=right>| . $locale->text('Period') . qq|</th>
812
      <td colspan=3>
813
      <select data-dojo-type="dijit/form/Select" id=month name=month>$form->{selectaccountingmonth}</select>
814
      <select data-dojo-type="dijit/form/Select" id=year name=year>$form->{selectaccountingyear}</select>
815
      <input name=interval class=radio type=radio data-dojo-type="dijit/form/RadioButton" value=0 checked>&nbsp;|
816
          . $locale->text('Current') . qq|
817
      <input name=interval class=radio type=radio data-dojo-type="dijit/form/RadioButton" value=1>&nbsp;|
818
          . $locale->text('Month') . qq|
819
      <input name=interval class=radio type=radio data-dojo-type="dijit/form/RadioButton" value=3>&nbsp;|
820
          . $locale->text('Quarter') . qq|
821
      <input name=interval class=radio type=radio data-dojo-type="dijit/form/RadioButton" value=12>&nbsp;|
822
          . $locale->text('Year') . qq|
823
      </td>
824
    </tr>
825
|;
826
    }
827

828
    $fromto = qq|
1✔
829
        <tr>
830
      <th align=right nowrap>| . $locale->text('Transaction Dates') . qq|</th>
831
      <td>|
832
      . $locale->text('From')
833
      . qq| <input class="date" data-dojo-type="lsmb/DateTextBox" name=transdatefrom size=11 title="$myconfig{dateformat}">
834
      |
835
      . $locale->text('To')
836
      . qq| <input class="date" data-dojo-type="lsmb/DateTextBox" name=transdateto size=11 title="$myconfig{dateformat}"></td>
837
    </tr>
838
    $selectfrom
839
|;
840

841
    if ( @{ $form->{all_project} } ) {
1✔
842
        $form->{selectprojectnumber} = "<option></option>\n";
1✔
843
        for ( @{ $form->{all_project} } ) {
1✔
844
            $form->{selectprojectnumber} .=
845
qq|<option value="$_->{control_code}--$_->{id}">$_->{control_code}--$_->{description}</option>\n|;
1✔
846
        }
847
    }
848
    else {
849
        $form->error( $locale->text('No open Projects!') );
×
850
    }
851

852
    if ( @{ $form->{all_employee} } ) {
1✔
853
        $form->{selectemployee} = "<option></option>\n";
1✔
854
        for ( @{ $form->{all_employee} } ) {
1✔
855
            $form->{selectemployee} .=
856
              qq|<option value="$_->{name}--$_->{id}">$_->{name}</option>\n|;
1✔
857
        }
858

859
        $employee = qq|
1✔
860
              <tr>
861
            <th align=right nowrap>| . $locale->text('Employee') . qq|</th>
862
        <td><select data-dojo-type="dijit/form/Select" id=employee name=employee>$form->{selectemployee}</select></td>
863
          </tr>
864
|;
865
    }
866

867
    $form->{title} = $locale->text('Generate Sales Orders');
1✔
868
    $form->{vc}    = "customer";
1✔
869
    $form->{type}  = "sales_order";
1✔
870

871
    $form->header;
1✔
872

873
    print qq|
1✔
874
<body class="lsmb">
875

876
<form id="timecard-generate-salesorders" method="post" data-dojo-type="lsmb/Form" action=$form->{script}>
877

878
<table width=100%>
879
  <tr>
880
    <th class=listtop>$form->{title}</th>
881
  </tr>
882
  <tr height="5"></tr>
883
  <tr valign=top>
884
    <td>
885
      <table>
886
        <tr>
887
      <th align=right>| . $locale->text('Project') . qq|</th>
888
      <td colspan=3><select data-dojo-type="dijit/form/Select" id=projectnumber name=projectnumber>$form->{selectprojectnumber}</select></td>
889
    </tr>
890
    $employee
891
    $fromto
892
    <tr>
893
      <th></th>
894
        <td><input name=summary type=radio data-dojo-type="dijit/form/RadioButton" class=radio value=1> |
895
      . $locale->text('Summary') . qq|
896
        <input name=summary type=radio data-dojo-type="dijit/form/RadioButton" class=radio value=0 checked> |
897
      . $locale->text('Detail') . qq|
898
        </td>
899
      </tr>
900
      </table>
901
    </td>
902
  </tr>
903
  <tr>
904
    <td><hr size=3 noshade></td>
905
  </tr>
906
</table>
907

908
|;
909

910
    $form->{nextsub} = "project_jcitems_list";
1✔
911
    $form->hide_form(qw(path login sessionid nextsub type vc));
1✔
912

913
    print qq|
1✔
914
<button data-dojo-type="dijit/form/Button" type="submit" class="submit" name="action" value="continue">|
915
      . $locale->text('Continue')
916
      . qq|</button>
917

918
</form>
919
|;
920

921
    print qq|
1✔
922

923
</body>
924
</html>
925
|;
926

927
}
928

929
sub project_jcitems_list {
930

931
    $form->{projectnumber} = $form->unescape( $form->{projectnumber} );
×
932
    $form->{employee}      = $form->unescape( $form->{employee} );
×
933
    $form->{callback}      = "$form->{script}?action=project_jcitems_list";
×
934
    for (
×
935
        qw(month year interval summary transdatefrom transdateto login path sessionid nextsub type vc)
936
      )
937
    {
938
        $form->{callback} .= "&$_=$form->{$_}";
×
939
    }
940
    for (qw(employe projectnumber)) {
×
941
        $form->{callback} .= "&$_=" . $form->escape( $form->{$_}, 1 );
×
942
    }
943

944
    PE->get_jcitems( \%myconfig, \%$form );
×
945

946
    # flatten array
947
    $i = 1;
×
948
    foreach my $ref ( @{ $form->{jcitems} } ) {
×
949
        if ( $form->{summary} ) {
×
950

951
            $thisitem =
×
952
              qq|$ref->{project_id}:$ref->{"$form->{vc}_id"}:$ref->{parts_id}|;
953

954
            if ( $thisitem eq $sameitem ) {
×
955

956
                $i--;
×
957
                for (qw(qty amount)) { $form->{"${_}_$i"} += $ref->{$_} }
×
958
                $form->{"id_$i"} .= " $ref->{id}:$ref->{qty}";
×
959
                if ( $form->{"notes_$i"} ) {
×
960
                    $form->{"notes_$i"} .= qq|\n\n$ref->{notes}|;
×
961
                }
962
                else {
963
                    $form->{"notes_$i"} = $ref->{notes};
×
964
                }
965

966
            }
967
            else {
968

969
                for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} }
×
970

971
                $form->{"checked_$i"}     = 1;
×
972
                $form->{"$form->{vc}_$i"} = $ref->{ $form->{vc} };
×
973
                $form->{"id_$i"}          = "$ref->{id}:$ref->{qty}";
×
974

975
            }
976

977
            $sameitem =
×
978
              qq|$ref->{project_id}:$ref->{"$form->{vc}_id"}:$ref->{parts_id}|;
979
        }
980
        else {
981

982
            for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} }
×
983
            $form->{"checked_$i"} = 1;
×
984
            $form->{"id_$i"}      = "$ref->{id}:$ref->{qty}";
×
985

986
        }
987

988
        $i++;
×
989

990
    }
991

992
    $form->{rowcount} = $i - 1;
×
993

994
    foreach my $i ( 1 .. $form->{rowcount} ) {
×
995
        for (qw(qty allocated)) {
×
996
            $form->{"${_}_$i"} =
997
              $form->format_amount( \%myconfig, $form->{"${_}_$i"} );
×
998
        }
999
        for (qw(amount sellprice)) {
×
1000
            $form->{"${_}_$i"} =
1001
              $form->format_amount( \%myconfig, $form->{"${_}_$i"}, 2 );
×
1002
        }
1003
    }
1004

1005
    &jcitems;
×
1006

1007
}
1008

1009
sub jcitems {
1010

1011
    # $locale->text('Customer')
1012
    # $locale->text('Vendor')
1013

1014
    $vc = ucfirst $form->{vc};
×
1015

1016
    @column_index = qw(id projectnumber name);
×
1017
    if ( !$form->{summary} ) {
×
1018
        push @column_index, qw(transdate);
×
1019
    }
1020
    push @column_index, qw(partnumber description qty amount);
×
1021

1022
    $column_header{id} = qq|<th>&nbsp;</th>|;
×
1023
    $column_header{transdate} =
1024
      qq|<th class=listheading>| . $locale->text('Date') . qq|</th>|;
×
1025
    $column_header{partnumber} =
1026
        qq|<th class=listheading>|
×
1027
      . $locale->text('Service Code')
1028
      . qq|<br>|
1029
      . $locale->text('Part Number')
1030
      . qq|</th>|;
1031
    $column_header{projectnumber} =
1032
      qq|<th class=listheading>| . $locale->text('Project Number') . qq|</th>|;
×
1033
    $column_header{description} =
1034
      qq|<th class=listheading>| . $locale->text('Description') . qq|</th>|;
×
1035
    $column_header{name} = qq|<th class=listheading>$vc</th>|;
×
1036
    $column_header{qty} =
1037
      qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
×
1038
    $column_header{amount} =
1039
      qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
×
1040

1041
    if ( $form->{type} eq 'sales_order' ) {
×
1042
        $form->{title} = $locale->text('Generate Sales Orders');
×
1043
    }
1044

1045
    $form->header;
×
1046

1047
    print qq|
×
1048
<body class="lsmb">
1049

1050
<form method="post" data-dojo-type="lsmb/Form" action=$form->{script}>
1051

1052
<table width=100%>
1053
  <tr>
1054
    <th class=listtop>$form->{title}</th>
1055
  </tr>
1056
  <tr height="5"></tr>
1057
  <tr>
1058
    <td>
1059
      <table width=100%>
1060
        <tr class=listheading>|;
1061

1062
    for (@column_index) { print "\n$column_header{$_}" }
×
1063

1064
    print qq|
×
1065
        </tr>
1066
|;
1067

1068
    foreach my $i ( 1 .. $form->{rowcount} ) {
×
1069

1070
        for (@column_index) {
×
1071
            $column_data{$_} = qq|<td>$form->{"${_}_$i"}</td>|;
×
1072
        }
1073
        for (qw(qty amount)) {
×
1074
            $column_data{$_} = qq|<td align=right>$form->{"${_}_$i"}</td>|;
×
1075
        }
1076

1077
        $checked = ( $form->{"checked_$i"} ) ? "checked" : "";
×
1078
        $column_data{id} =
1079
qq|<td><input name="checked_$i" class=checkbox type=checkbox data-dojo-type="dijit/form/CheckBox" value="1" $checked></td>|;
×
1080

1081
        if ( $form->{"$form->{vc}_id_$i"} ) {
×
1082
            $column_data{name} = qq|<td>$form->{"$form->{vc}_$i"}</td>|;
×
1083
            $form->hide_form( "$form->{vc}_id_$i", "$form->{vc}_$i" );
×
1084
        }
1085
        else {
1086
            $column_data{name} =
1087
qq|<td><input name="ndx_$i" class=checkbox type=checkbox data-dojo-type="dijit/form/CheckBox" value="1"></td>|;
×
1088
        }
1089

1090
        for (qw(projectnumber partnumber description notes)) {
×
1091
            $form->{"${_}_$i"} = $form->quote( $form->{"${_}_$i"} );
×
1092
        }
1093
        $form->hide_form( map { "${_}_$i" }
×
1094
              qw(id project_id parts_id projectnumber transdate partnumber description notes qty amount taxaccounts sellprice)
1095
        );
1096

1097
        $j++;
×
1098
        $j %= 2;
×
1099
        print "
×
1100
        <tr class=listrow$j>";
1101

1102
        for (@column_index) { print "\n$column_data{$_}" }
×
1103

1104
        print qq|
×
1105
        </tr>
1106
|;
1107

1108
    }
1109

1110
    print qq|
×
1111
      </table>
1112
    </td>
1113
  </tr>
1114

1115
  <tr>
1116
    <td><hr size=3 noshade></td>
1117
  </tr>
1118
</table>
1119

1120
<br>
1121
|;
1122

1123
    $form->hide_form(
×
1124
        qw(path login sessionid vc nextsub rowcount type currency defaultcurrency taxaccounts summary callback)
1125
    );
1126

1127
    for ( split / /, $form->{taxaccounts} ) { $form->hide_form("${_}_rate") }
×
1128

1129
    if ( $form->{rowcount} ) {
×
1130
        print qq|
×
1131
<button data-dojo-type="dijit/form/Button" class="submit" type="submit" name="action" value="generate_sales_orders">|
1132
          . $locale->text('Generate Sales Orders')
1133
          . qq|</button>|;
1134

1135
        print qq|
×
1136
<button data-dojo-type="dijit/form/Button" class="submit" type="submit" name="action" value="select_customer">|
1137
          . $locale->text('Select Customer')
1138
          . qq|</button>|;
1139

1140
    }
1141

1142
    print qq|
×
1143
</form>
1144

1145
</body>
1146
</html>
1147
|;
1148

1149
}
1150

1151
sub select_customer {
1152

1153
    for ( 1 .. $form->{rowcount} ) {
×
1154
        last if ( $ok = $form->{"ndx_$_"} );
×
1155
    }
1156

1157
    $form->error( $locale->text('Nothing selected!') ) unless $ok;
×
1158

1159
    $label =
1160
      ( $form->{vc} eq 'customer' )
×
1161
      ? $locale->text('Customer')
1162
      : $locale->text('Vendor');
1163

1164
    $form->header;
×
1165

1166
    print qq|
×
1167
<body class="lsmb $form->{dojo_theme}" onLoad="document.forms[0].$form->{vc}.focus()" />
1168

1169
<form method="post" data-dojo-type="lsmb/Form" action=$form->{script}>
1170

1171
<b>$label</b> <input data-dojo-type="dijit/form/TextBox" name=$form->{vc} size=40>
1172

1173
|;
1174

1175
    $form->{nextsub} = "$form->{vc}_selected";
×
1176
    $form->{action}  = "$form->{vc}_selected";
×
1177

1178
    $form->hide_form;
×
1179

1180
    print qq|
×
1181
<button data-dojo-type="dijit/form/Button" class="submit" type="submit" name="action" value="continue">|
1182
      . $locale->text('Continue')
1183
      . qq|</button>
1184

1185
</form>
1186
|;
1187

1188
    print qq|
×
1189

1190
</body>
1191
</html>
1192
|;
1193

1194
}
1195

1196
sub customer_selected {
1197

1198
    if (
×
1199
        (
1200
            $rv = $form->get_name( \%myconfig, $form->{vc}, $form->{startdate} )
1201
        ) > 1
1202
      )
1203
    {
1204
        &select_name( $form->{vc} );
×
1205
        $form->finalize_request();
×
1206
    }
1207

1208
    if ( $rv == 1 ) {
×
1209
        $form->{"$form->{vc}"}    = $form->{name_list}[0]->{name};
×
1210
        $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id};
×
1211
    }
1212
    else {
1213
        $msg =
1214
          ( $form->{vc} eq 'customer' )
×
1215
          ? $locale->text('Customer not on file!')
1216
          : $locale->text('Vendor not on file!');
1217
        $form->error($msg);
×
1218
    }
1219

1220
    &display_form;
×
1221

1222
}
1223

1224
sub sales_order_header {
1225

1226
    for ( 1 .. $form->{rowcount} ) {
×
1227
        if ( $form->{"ndx_$_"} ) {
×
1228
            $form->{"$form->{vc}_id_$_"} = $form->{"$form->{vc}_id"};
×
1229
            $form->{"$form->{vc}_$_"}    = $form->{"$form->{vc}"};
×
1230
        }
1231
    }
1232

1233
}
1234

1235
sub sales_order_footer { &jcitems }
×
1236

1237
sub generate_sales_orders {
1238

1239
    foreach my $i ( 1 .. $form->{rowcount} ) {
×
1240
        $form->error( $locale->text('Customer missing!') )
1241
          if ( $form->{"checked_$i"} && !$form->{"customer_$i"} );
×
1242
    }
1243

1244
    foreach my $i ( 1 .. $form->{rowcount} ) {
×
1245
        if ( $form->{"checked_$i"} ) {
×
1246
            push @{ $form->{order}{qq|$form->{"customer_id_$i"}|} },
×
1247
              {
1248
                partnumber    => $form->{"partnumber_$i"},
1249
                id            => $form->{"parts_id_$i"},
1250
                description   => $form->{"description_$i"},
1251
                qty           => $form->{"qty_$i"},
1252
                sellprice     => $form->{"sellprice_$i"},
1253
                projectnumber => qq|--$form->{"project_id_$i"}|,
1254
                reqdate       => $form->{"transdate_$i"},
1255
                taxaccounts   => $form->{"taxaccounts_$i"},
1256
                jcitems       => $form->{"id_$i"},
1257
                notes         => $form->{"notes_$i"},
×
1258
              };
1259
        }
1260
    }
1261

1262
    $order = Form->new;
×
1263
    for ( keys %{ $form->{order} } ) {
×
1264
        $order->{dbh} = $form->{dbh};
×
1265

1266
        for (qw(type vc defaultcurrency login)) { $order->{$_} = $form->{$_} }
×
1267
        for ( split / /, $form->{taxaccounts} ) {
×
1268
            $order->{"${_}_rate"} = $form->{"${_}_rate"};
×
1269
        }
1270

1271
        $i = 0;
×
1272
        $order->{"$order->{vc}_id"} = $_;
×
1273

1274
        AA->get_name( \%myconfig, \%$order );
×
1275

1276
        foreach my $ref ( @{ $form->{order}{$_} } ) {
×
1277
            $i++;
×
1278

1279
            for ( keys %$ref ) { $order->{"${_}_$i"} = $ref->{$_} }
×
1280

1281
            $taxaccounts = "";
×
1282
            for ( split / /, $order->{taxaccounts} ) {
×
1283
                $taxaccounts .= qq|$_ |
×
1284
                  if ( $_ =~ /$order->{"taxaccounts_$i"}/ );
1285
            }
1286
            $order->{"taxaccounts_$i"} = $taxaccounts;
×
1287

1288
        }
1289
        $order->{rowcount} = $i;
×
1290

1291
        for (qw(currency)) { $order->{$_} = $form->{$_} }
×
1292

1293
        $order->{ordnumber} = $order->update_defaults( \%myconfig, 'sonumber' );
×
1294
        $order->{transdate} = $order->current_date( \%myconfig );
×
1295
        $order->{reqdate}   = $order->{transdate};
×
1296

1297
        for (qw(intnotes employee employee_id)) { delete $order->{$_} }
×
1298

1299
        PE->timecard_get_currency( \%$order );
×
1300

1301
        if ( OE->save( \%myconfig, \%$order ) ) {
×
1302
            if ( !PE->allocate_projectitems( \%myconfig, \%$order ) ) {
×
1303
                OE->delete( \%myconfig, \%$order,
×
1304
                            LedgerSMB::Sysconfig::spool() );
1305
            }
1306
        }
1307
        else {
1308
            $order->error( $locale->text('Failed to save order!') );
×
1309
        }
1310

1311
        for ( keys %$order ) { delete $order->{$_} }
×
1312

1313
    }
1314

1315
    $form->redirect( $locale->text('Orders generated!') );
×
1316

1317
}
1318

1319
1;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2024 Coveralls, Inc