| Conditions | 9 |
| Paths | 16 |
| Total Lines | 326 |
| Code Lines | 169 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 326 | public static function output2( $post ) { |
||
| 327 | |||
| 328 | // Prepare the invoice. |
||
| 329 | $invoice = new WPInv_Invoice( $post ); |
||
| 330 | |||
| 331 | // Invoice items. |
||
| 332 | $items = $invoice->get_items(); |
||
| 333 | |||
| 334 | $totals = array( |
||
| 335 | |||
| 336 | 'subtotal' => array( |
||
| 337 | 'label' => __( 'Items Subtotal', 'invoicing' ), |
||
| 338 | 'value' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ), |
||
| 339 | ), |
||
| 340 | |||
| 341 | 'discount' => array( |
||
| 342 | 'label' => __( 'Total Discount', 'invoicing' ), |
||
| 343 | 'value' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
||
| 344 | ), |
||
| 345 | |||
| 346 | 'tax' => array( |
||
| 347 | 'label' => __( 'Total Tax', 'invoicing' ), |
||
| 348 | 'value' => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ), |
||
| 349 | ), |
||
| 350 | |||
| 351 | 'total' => array( |
||
| 352 | 'label' => __( 'Invoice Total', 'invoicing' ), |
||
| 353 | 'value' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ), |
||
| 354 | ) |
||
| 355 | ); |
||
| 356 | |||
| 357 | if ( ! wpinv_use_taxes() ) { |
||
| 358 | unset( $totals['tax'] ); |
||
| 359 | } |
||
| 360 | |||
| 361 | $item_args = array( |
||
| 362 | 'post_type' => 'wpi_item', |
||
| 363 | 'orderby' => 'title', |
||
| 364 | 'order' => 'ASC', |
||
| 365 | 'posts_per_page' => -1, |
||
| 366 | 'post_status' => array( 'publish' ), |
||
| 367 | 'meta_query' => array( |
||
| 368 | array( |
||
| 369 | 'key' => '_wpinv_type', |
||
| 370 | 'compare' => '!=', |
||
| 371 | 'value' => 'package' |
||
| 372 | ) |
||
| 373 | ) |
||
| 374 | ); |
||
| 375 | |||
| 376 | ?> |
||
| 377 | |||
| 378 | <style> |
||
| 379 | #poststuff .input-group-text, |
||
| 380 | #poststuff .form-control { |
||
| 381 | border-color: #7e8993; |
||
| 382 | } |
||
| 383 | |||
| 384 | #wpinv-details label { |
||
| 385 | margin-bottom: 3px; |
||
| 386 | font-weight: 600; |
||
| 387 | } |
||
| 388 | </style> |
||
| 389 | |||
| 390 | <div class="bsui getpaid-invoice-items-inner <?php echo sanitize_html_class( $invoice->get_template( 'edit' ) ); ?> <?php echo empty( $items ) ? 'no-items' : 'has-items'; ?> <?php echo $invoice->is_paid() || $invoice->is_refunded() ? 'not-editable' : 'editable'; ?>" style="margin-top: 1.5rem"> |
||
| 391 | |||
| 392 | <?php if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) : ?> |
||
| 393 | <?php do_action( 'wpinv_meta_box_before_invoice_template_row', $invoice->get_id() ); ?> |
||
| 394 | |||
| 395 | <div class="row"> |
||
| 396 | <div class="col-12 col-sm-6"> |
||
| 397 | <?php |
||
| 398 | echo aui()->select( |
||
| 399 | array( |
||
| 400 | 'id' => 'wpinv_template', |
||
| 401 | 'name' => 'wpinv_template', |
||
| 402 | 'label' => __( 'Template', 'invoicing' ), |
||
| 403 | 'label_type' => 'vertical', |
||
| 404 | 'placeholder' => __( 'Choose a template', 'invoicing' ), |
||
| 405 | 'class' => 'form-control-sm', |
||
| 406 | 'value' => $invoice->get_template( 'edit' ), |
||
| 407 | 'options' => array( |
||
| 408 | 'quantity' => __( 'Quantity', 'invoicing' ), |
||
| 409 | 'hours' => __( 'Hours', 'invoicing' ), |
||
| 410 | 'amount' => __( 'Amount Only', 'invoicing' ), |
||
| 411 | ), |
||
| 412 | 'data-allow-clear' => 'false', |
||
| 413 | 'select2' => true, |
||
| 414 | ) |
||
| 415 | ); |
||
| 416 | ?> |
||
| 417 | </div> |
||
| 418 | <div class="col-12 col-sm-6"> |
||
| 419 | <?php |
||
| 420 | |||
| 421 | // Set currency. |
||
| 422 | echo aui()->select( |
||
| 423 | array( |
||
| 424 | 'id' => 'wpinv_currency', |
||
| 425 | 'name' => 'wpinv_currency', |
||
| 426 | 'label' => __( 'Currency', 'invoicing' ), |
||
| 427 | 'label_type' => 'vertical', |
||
| 428 | 'placeholder' => __( 'Select Invoice Currency', 'invoicing' ), |
||
| 429 | 'class' => 'form-control-sm', |
||
| 430 | 'value' => $invoice->get_currency( 'edit' ), |
||
| 431 | 'required' => false, |
||
| 432 | 'data-allow-clear' => 'false', |
||
| 433 | 'select2' => true, |
||
| 434 | 'options' => wpinv_get_currencies(), |
||
| 435 | ) |
||
| 436 | ); |
||
| 437 | |||
| 438 | ?> |
||
| 439 | </div> |
||
| 440 | </div> |
||
| 441 | |||
| 442 | <?php do_action( 'wpinv_meta_box_invoice_template_row', $invoice->get_id() ); ?> |
||
| 443 | <?php endif; ?> |
||
| 444 | |||
| 445 | <table cellpadding="0" cellspacing="0" class="getpaid_invoice_items"> |
||
| 446 | <thead> |
||
| 447 | <tr> |
||
| 448 | <th class="getpaid-item" colspan="2"><?php _e( 'Item', 'invoicing' ) ?></th> |
||
| 449 | <th class="getpaid-quantity hide-if-amount text-right"> |
||
| 450 | <span class="getpaid-hide-if-hours"><?php _e( 'Quantity', 'invoicing' ) ?></span> |
||
| 451 | <span class="getpaid-hide-if-quantity"><?php _e( 'Hours', 'invoicing' ) ?></span> |
||
| 452 | </th> |
||
| 453 | <th class="getpaid-price hide-if-amount text-right"> |
||
| 454 | <span class="getpaid-hide-if-hours"><?php _e( 'Price', 'invoicing' ) ?></span> |
||
| 455 | <span class="getpaid-hide-if-quantity"><?php _e( 'Rate', 'invoicing' ) ?></span> |
||
| 456 | </th> |
||
| 457 | <th class="getpaid-item-subtotal text-right"> |
||
| 458 | <span class="getpaid-hide-if-hours getpaid-hide-if-quantity"><?php _e( 'Amount', 'invoicing' ) ?></span> |
||
| 459 | <span class="hide-if-amount"><?php _e( 'Total', 'invoicing' ) ?></span> |
||
| 460 | </th> |
||
| 461 | <th class="getpaid-item-actions hide-if-not-editable" width="70px"> </th> |
||
| 462 | </tr> |
||
| 463 | </thead> |
||
| 464 | <tbody class="getpaid_invoice_line_items"> |
||
| 465 | <tr class="hide-if-has-items hide-if-not-editable"> |
||
| 466 | <td colspan="2" class="pt-4 pb-4"> |
||
| 467 | <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php _e( 'Add Existing Items', 'invoicing' ) ?></button> |
||
| 468 | <button type="button" class="button button-secondary create-invoice-item" data-toggle="modal" data-target="#getpaid-create-invoice-item"><?php _e( 'Create New Item', 'invoicing' ) ?></button> |
||
| 469 | </td> |
||
| 470 | <td class="hide-if-amount"> </th> |
||
| 471 | <td class="hide-if-amount"> </th> |
||
| 472 | <td> </th> |
||
| 473 | <td width="1%"> </th> |
||
| 474 | </tr> |
||
| 475 | <tr class="getpaid-invoice-item-template d-none"> |
||
| 476 | <td class="getpaid-item" colspan="2"> |
||
| 477 | <span class='item-name'></span> |
||
| 478 | <small class="form-text text-muted item-description"></small> |
||
| 479 | </td> |
||
| 480 | <td class="getpaid-quantity hide-if-amount text-right item-quantity"></td> |
||
| 481 | <td class="getpaid-price hide-if-amount text-right item-price"></td> |
||
| 482 | <td class="getpaid-item-subtotal text-right"> |
||
| 483 | <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"></span> |
||
| 484 | <span class="hide-if-amount item-total"></span> |
||
| 485 | </td> |
||
| 486 | <td class="getpaid-item-actions hide-if-not-editable" width="70px"> |
||
| 487 | <span class="dashicons dashicons-edit"></span> |
||
| 488 | <span class="dashicons dashicons-trash"></span> |
||
| 489 | </td> |
||
| 490 | </tr> |
||
| 491 | |||
| 492 | </tbody> |
||
| 493 | </table> |
||
| 494 | |||
| 495 | <div class="getpaid-invoice-totals-row"> |
||
| 496 | <div class="row"> |
||
| 497 | <div class="col-12 col-sm-6 offset-sm-6"> |
||
| 498 | <table class="getpaid-invoice-totals text-right w-100"> |
||
| 499 | <tbody> |
||
| 500 | <?php foreach ( apply_filters( 'getpaid_invoice_subtotal_rows', $totals, $invoice ) as $key => $data ) : ?> |
||
| 501 | <tr class="getpaid-totals-<?php echo sanitize_html_class( $key ); ?>"> |
||
| 502 | <td class="label"><?php echo sanitize_text_field( $data['label'] ) ?>:</td> |
||
| 503 | <td width="1%"></td> |
||
| 504 | <td class="value"><?php echo wp_kses_post( $data['value'] ) ?></td> |
||
| 505 | </tr> |
||
| 506 | <?php endforeach; ?> |
||
| 507 | </tbody> |
||
| 508 | </table> |
||
| 509 | </div> |
||
| 510 | </div> |
||
| 511 | </div> |
||
| 512 | |||
| 513 | <!-- Actions --> |
||
| 514 | <div class="getpaid-invoice-item-actions hide-if-no-items hide-if-not-editable"> |
||
| 515 | <div class="row"> |
||
| 516 | <div class="text-left col-12 col-sm-8"> |
||
| 517 | <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php _e( 'Add Existing Item', 'invoicing' ) ?></button> |
||
| 518 | <button type="button" class="button button-secondary create-invoice-item" data-toggle="modal" data-target="#getpaid-create-invoice-item"><?php _e( 'Create New Item', 'invoicing' ) ?></button> |
||
| 519 | <?php do_action( 'getpaid-invoice-items-actions', $invoice ); ?> |
||
| 520 | </div> |
||
| 521 | <div class="text-right col-12 col-sm-4"> |
||
| 522 | <button type="button" class="button button-primary recalculate-totals-button"><?php _e( 'Recalculate Totals', 'invoicing' ) ?></button> |
||
| 523 | </div> |
||
| 524 | </div> |
||
| 525 | </div> |
||
| 526 | |||
| 527 | <div class="getpaid-invoice-item-actions hide-if-editable"> |
||
| 528 | <p class="description m-2 text-right text-muted"><?php _e( 'This invoice is no longer editable', 'invoicing' ); ?></p> |
||
| 529 | </div> |
||
| 530 | |||
| 531 | <!-- Add items to an invoice --> |
||
| 532 | <div class="modal fade" id="getpaid-add-items-to-invoice" tabindex="-1" role="dialog" aria-labelledby="getpaid-add-item-to-invoice-label" aria-hidden="true"> |
||
| 533 | <div class="modal-dialog modal-dialog-centered" role="document"> |
||
| 534 | <div class="modal-content"> |
||
| 535 | <div class="modal-header"> |
||
| 536 | <h5 class="modal-title" id="getpaid-add-item-to-invoice-label"><?php _e( "Add Item(s)", 'invoicing' ); ?></h5> |
||
| 537 | <button type="button" class="close" data-dismiss="modal" aria-label="<?php _e( "Close", 'invoicing' ); ?>"> |
||
| 538 | <span aria-hidden="true">×</span> |
||
| 539 | </button> |
||
| 540 | </div> |
||
| 541 | <div class="modal-body"> |
||
| 542 | <table class="widefat"> |
||
| 543 | <thead> |
||
| 544 | <tr> |
||
| 545 | <th class="pl-0 text-left"><?php _e( 'Item', 'invoicing' ) ?></th> |
||
| 546 | <th class="pr-0 text-right hide-if-amount"> |
||
| 547 | <span class="getpaid-hide-if-hours"><?php _e( 'Quantity', 'invoicing' ) ?></span> |
||
| 548 | <span class="getpaid-hide-if-quantity"><?php _e( 'Hours', 'invoicing' ) ?></span> |
||
| 549 | </th> |
||
| 550 | </tr> |
||
| 551 | </thead> |
||
| 552 | <tbody> |
||
| 553 | <tr> |
||
| 554 | <td class="pl-0 text-left"> |
||
| 555 | <select class="regular-text getpaid-add-invoice-item-select"> |
||
| 556 | <option value="" selected="selected" disabled><?php esc_html_e( 'Select an item…', 'invoicing' ); ?></option> |
||
| 557 | <?php foreach ( get_posts( $item_args ) as $item ) : ?> |
||
| 558 | <option value="<?php echo (int) $item->ID; ?>"><?php echo strip_tags( $item->post_title ); ?></option> |
||
| 559 | <?php endforeach; ?> |
||
| 560 | </select> |
||
| 561 | </td> |
||
| 562 | <td class="pr-0 text-right hide-if-amount"> |
||
| 563 | <input type="number" class="w100" step="1" min="1" autocomplete="off" value="1" placeholder="1"> |
||
| 564 | </td> |
||
| 565 | </tr> |
||
| 566 | </tbody> |
||
| 567 | </table> |
||
| 568 | </div> |
||
| 569 | <div class="modal-footer"> |
||
| 570 | <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php _e( 'Cancel', 'invoicing' ); ?></button> |
||
| 571 | <button type="button" class="btn btn-primary getpaid-add" data-dismiss="modal"><?php _e( 'Add', 'invoicing' ); ?></button> |
||
| 572 | </div> |
||
| 573 | </div> |
||
| 574 | </div> |
||
| 575 | </div> |
||
| 576 | |||
| 577 | <!-- Create invoice item --> |
||
| 578 | <div class="modal fade" id="getpaid-create-invoice-item" tabindex="-1" role="dialog" aria-labelledby="getpaid-create-invoice-item-label" aria-hidden="true"> |
||
| 579 | <div class="modal-dialog modal-dialog-centered" role="document"> |
||
| 580 | <div class="modal-content"> |
||
| 581 | <div class="modal-header"> |
||
| 582 | <h5 class="modal-title" id="getpaid-create-invoice-item-label"><?php _e( "Create Item", 'invoicing' ); ?></h5> |
||
| 583 | <button type="button" class="close" data-dismiss="modal" aria-label="<?php _e( "Close", 'invoicing' ); ?>"> |
||
| 584 | <span aria-hidden="true">×</span> |
||
| 585 | </button> |
||
| 586 | </div> |
||
| 587 | <div class="modal-body"> |
||
| 588 | <div class="getpaid-create-item-div"> |
||
| 589 | <input type="hidden" name="id" value="new" class="form-control form-control-sm item-id"> |
||
| 590 | <label class="form-group w-100"> |
||
| 591 | <span><?php _e( 'Name', 'invoicing' ); ?></span> |
||
| 592 | <input type="text" name="name" placeholder="<?php esc_attr_e( 'Item Name', 'invoicing' ); ?>" class="form-control form-control-sm item-name"> |
||
| 593 | </label> |
||
| 594 | <label class="form-group w-100"> |
||
| 595 | <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php _e( 'Amount', 'invoicing' ); ?></span> |
||
| 596 | <span class="hide-if-amount"><?php _e( 'Price', 'invoicing' ); ?></span> |
||
| 597 | <input type="text" name="price" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" class="form-control form-control-sm item-price"> |
||
| 598 | </label> |
||
| 599 | <label class="form-group w-100 hide-if-amount"> |
||
| 600 | <span><?php _e( 'Quantity', 'invoicing' ); ?></span> |
||
| 601 | <input type="text" name="quantity" placeholder="1" class="form-control form-control-sm item-quantity"> |
||
| 602 | </label> |
||
| 603 | <label class="form-group w-100"> |
||
| 604 | <span><?php _e( 'Item Description', 'invoicing' ); ?></span> |
||
| 605 | <textarea name="description" placeholder="<?php esc_attr_e( 'Enter a description for this item', 'invoicing' ); ?>" class="form-control item-description"></textarea> |
||
| 606 | </label> |
||
| 607 | </div> |
||
| 608 | </div> |
||
| 609 | <div class="modal-footer"> |
||
| 610 | <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php _e( 'Cancel', 'invoicing' ); ?></button> |
||
| 611 | <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php _e( 'Create', 'invoicing' ); ?></button> |
||
| 612 | </div> |
||
| 613 | </div> |
||
| 614 | </div> |
||
| 615 | </div> |
||
| 616 | |||
| 617 | <!-- Edit invoice item --> |
||
| 618 | <div class="modal fade" id="getpaid-edit-invoice-item" tabindex="-1" role="dialog" aria-labelledby="getpaid-edit-invoice-item-label" aria-hidden="true"> |
||
| 619 | <div class="modal-dialog modal-dialog-centered" role="document"> |
||
| 620 | <div class="modal-content"> |
||
| 621 | <div class="modal-header"> |
||
| 622 | <h5 class="modal-title" id="getpaid-edit-invoice-item-label"><?php _e( "Edit Item", 'invoicing' ); ?></h5> |
||
| 623 | <button type="button" class="close" data-dismiss="modal" aria-label="<?php _e( "Close", 'invoicing' ); ?>"> |
||
| 624 | <span aria-hidden="true">×</span> |
||
| 625 | </button> |
||
| 626 | </div> |
||
| 627 | <div class="modal-body"> |
||
| 628 | <div class="getpaid-edit-item-div"> |
||
| 629 | <input type="hidden" name="id" class="form-control form-control-sm item-id"> |
||
| 630 | <label class="form-group w-100"> |
||
| 631 | <span><?php _e( 'Name', 'invoicing' ); ?></span> |
||
| 632 | <input type="text" name="name" placeholder="<?php esc_attr_e( 'Item Name', 'invoicing' ); ?>" class="form-control form-control-sm item-name"> |
||
| 633 | </label> |
||
| 634 | <label class="form-group w-100"> |
||
| 635 | <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php _e( 'Amount', 'invoicing' ); ?></span> |
||
| 636 | <span class="hide-if-amount"><?php _e( 'Price', 'invoicing' ); ?></span> |
||
| 637 | <input type="text" name="price" placeholder="<?php wpinv_sanitize_amount( 0 ); ?>" class="form-control form-control-sm item-price"> |
||
| 638 | </label> |
||
| 639 | <label class="form-group w-100 hide-if-amount"> |
||
| 640 | <span><?php _e( 'Quantity', 'invoicing' ); ?></span> |
||
| 641 | <input type="text" name="quantity" placeholder="1" class="form-control form-control-sm item-quantity"> |
||
| 642 | </label> |
||
| 643 | <label class="form-group w-100"> |
||
| 644 | <span><?php _e( 'Item Description', 'invoicing' ); ?></span> |
||
| 645 | <textarea name="description" placeholder="<?php esc_attr_e( 'Enter a description for this item', 'invoicing' ); ?>" class="form-control item-description"></textarea> |
||
| 646 | </label> |
||
| 647 | </div> |
||
| 648 | </div> |
||
| 649 | <div class="modal-footer"> |
||
| 650 | <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php _e( 'Cancel', 'invoicing' ); ?></button> |
||
| 651 | <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php _e( 'Save', 'invoicing' ); ?></button> |
||
| 652 | </div> |
||
| 661 |